Spring注入的不同方式

1.直接创建一个Bean

<bean id="dboperate" class="study.spring2.Test"></bean>

2.通过IOC容器注入基本数据类型

<bean id="test" class="study.spring2.Test" init-method="init">
<property name="string_var" value="spring"></property>
<property name="int_var" value="99"></property>
<property name="shtor_var" value="100"></property>
<property name="char_var" value="a"></property>
<property name="long_var" value="99999999"></property>
<property name="double_var" value="99.999"></property>
<property name="boolean_var" value="false"></property>
</bean>

其中init-method是Bean实例对属性值注入后自动执行的。

3.注入引入数据类型

<bean id="runit" class="study.spring2.Runit">
<property name="test" ref="test"></property>
</bean>

4.注入null类型

<bean id="null_string" class="study.spring2.TestNull">
<property name="null_str">
<null />
</property>
</bean>

5.注入Properties类型

<!-- 注入Properties类型 -->
<bean id="test_properties" class="study.spring2.TestProperties">
<property name="properties">
<props>
<prop key="1">11</prop>
<prop key="2">22</prop>
<prop key="3">33</prop>
</props>
</property>
</bean>

6.对构造方法进行注入

<!-- 对构造方法进行注入 -->
<bean id="test_con" class="study.spring2.TestCon">
<constructor-arg type="java.lang.String" value="hello"></constructor-arg>
<constructor-arg type="java.lang.String" value="world"></constructor-arg>
</bean>
上一篇:ScrollView不能包含多个子项,ScrollView can host only one direct child


下一篇:通过settings.db自定义Android系统默认设置