JavaEE-SSM:021 Spring 使用XML装配Bean

1.添加XSD头

<?xml version='1.0' encoding='UTF-8' ?>
<beans xmlns = "http://www.springframework.org/schema/beans"
        xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation = "http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">
        <!--Spring相关配置-->
</beans>

 

2.装配简单值

id就是通过Spring找到bean的名称

class为类的全限定名称

property是属性,此类方式通过setter方法进行依赖注入

3.装配已存在的Bean

通过ref字段指定装配的其他bean

4.装配复杂类型(List、Map、Properties、Set、Array)

Array使用<array>进行装配,对每个item使用<value>value</value>进行装配

Set使用<set>进行装配,对每个item使用<value>value</value>进行装配

List使用<list>进行装配,对每个item使用<value>value</value>进行装配

Map使用<map>进行装配,对每个item使用<entry key=" " value=" " />进行装配

Properties使用<props>进行装配,每个item使用<prop key=" ">value</prop>进行装配

参照已经存在的bean进行复杂装配:

猜你喜欢

转载自blog.csdn.net/Day_and_Night_2017/article/details/84304010