Spring实战Day3

通过XML创建装配bean

1.装配不存在成员变量的bean


<bean id="talent" class="cn.jqzhong.Spring.study.day2.LiteraryTalent"></bean>

2.装配存在成员变量的bean

2.1通过构造器注入

2.1.1属性值为引用类型、引用类型列表

<bean id="people" class="cn.jqzhong.Spring.study.day2.LikeMePeople">
  <constructor-arg ref="talent"></constructor-arg><constructor-arg>
    <list>
      <ref bean=""></ref>
      <ref bean=""></ref>
    </list>
  </constructor-arg>
</bean>

2.1.2属性值为字面值、字面值类型列表

<bean id="people" class="cn.jqzhong.Spring.study.day2.LikeMePeople">
  <constructor-arg value="xxx"></constructor-arg>
  <constructor-arg>
    <list>
      <value>xxx</value>
      <value>xxx</value>
    </list>
  </constructor-arg>
</bean>

2.2通过属性设置

2.2.1属性值为引用类型、引用类型列表

<bean id="people" class="cn.jqzhong.Spring.study.day2.LikeMePeople">
  <property name="talent" ref="talent"></property>
  <property>
    <list>
      <ref bean=""></ref>
      <ref bean=""></ref>
    </list>
  </property>

</bean>

2.2.2属性值为属性值为字面值、字面值类型列表

<bean id="people" class="cn.jqzhong.Spring.study.day2.LikeMePeople">
  <property name="talent" value="xxx"></property>
  <property name="otherTlent">
    <list>
      <value>xxx</value>
      <value>xxx</value>
    </list>
  </property>
</bean>

猜你喜欢

转载自www.cnblogs.com/luo-bo/p/10520336.html