工廠注入: web
<bean id="xxx" class="x.x.x" factory-method="methodName" /> spring
Bean的做用域 session
<bean id="xxx" class="x.x.x" scope="scope" /> mvc
scope="prototype"---每次都產生一個新的實例 this
scope="singleton" spa
scope="request" 在1次HTTP請求中,每一個bean定義對應一個實例,該做用域僅僅在基於web的spring上下文 prototype
例如springmvc中才有效。 xml
session 在一個HTTP session中,每一個bean定義對應一個實例,該做用域僅僅在基於web的spring上下文中 作用域
例如springMVC中才有效 get
global-session 在一個全局HTTP session中,每一個bean定義對應一個實例,該做用域僅僅在基於portlet
上下文中才有效。
------
Bean的初始化和銷燬方法定義
<bean id="xxx" class="x.x.x" init-method="methodName" destroy-method="methodName"/>
經過Beans指定默認的init和destroy
<beans XXX
default-init-method="methodName" default-destroy-method="methodName">
...
經過getter和setter注入
<bean id="k" class="x.x.x" >
<property name="a" value="b"/>
<property name="c" ref="beanid"/>
<property name="ins"><bean class="" /> </property><!--內部Bean-->
</bean>
-----
<?xml version=」1.0」 encoding=」UTF-8」?>
<beans xmlns=http://www.springframework.org/schema/beans
xmlns:p="http://www.springframework.org/scheme/p"
xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
xmnls:aop="http://www.springframework.org/schema/aop"
Xsi:schemaLocation=」http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd」>
<bean id="x" class="" p:song="a" p:i-ref="b" />
裝配集合
<list> 裝配list類型的值,能夠重複
<set>裝配set類型的值,不能夠重複
<map>裝配map類型的值,名稱和值能夠是任何類型
<props>裝配properties類型的值,名稱和值必須都是在String類型
若是參數爲Collection<Type> ,List<Ins>或者Ins[] array時,能夠
<property name="xxx">
<list>
<ref bean="a"/>
<ref bean="b" />
<ref bean="c />
</list>
</property>
或者
<property name="xxx">
<set>
<ref bean="a"/>
<ref bean="b" />
<ref bean="c />
</set>
</property>
也能夠包含<value><bean><null/> 甚至再嵌套一個<list>
-------
<bean id="xxx" class="xxx">
<property name="x">
<map>
<entry key="x" value-ref="x" />
<entry key-ref="x" value-ref="x" />
<entry key="x" value="x" />
<entry key="x" value-ref="x" />
</map>
</property>
</bean>
---------
private Properties instruments;
public void setInstruments(Properties ins){
this.instruments=ins;
此時
<property name="ins>
<props>
<prop key="xxx">xxx</prop>
<prop key="xxx">xxx</prop>
<prop key="xxx">xxx</prop>
</props>
</property>
---
<property name="x"><null/></property>