……

Spring xml注入 以及 xml配置

Posted on 2020-09-17 22:20  ITOTone  阅读(284)  评论(0编辑  收藏  举报

xml  配置  

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:context="http://www.springframework.org/schema/context"
       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
   http://www.springframework.org/schema/tx
   http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context-3.0.xsd">
</beans>

注入方式

 <bean id="Addresa" class="com.cn.jieless.Addresa"/>

    <bean id="pojo" class="com.cn.jieless.pojo" name="pojo2">
        <!--第一种   普通值注入  直接使用value 赋值-->
        <property name="name" value="我是name"/>
        <!--第二种   bean注入   ref-->
        <property name="address" ref="Addresa"/>
        <!--第三种  数组注入-->
        <property name="books">
            <array>
                <value>西游记</value>
                <value>红楼梦</value>
                <value>三国演义</value>
                <value>水浒传</value>
            </array>
        </property>
        <!--第三种  List集合注入-->
        <property name="hobby">
            <list>
                <value>西游记List</value>
                <value>红楼梦List</value>
                <value>三国演义List</value>
                <value>水浒传List</value>
            </list>
        </property>
        <!--第三种  map集合注入-->
        <property name="card">
            <map>
                <entry key="身份证" value="4564645465465456678"></entry>
            </map>
        </property>
        <!--第三种  set注入-->
        <property name="wife">
            <set>
                <value>QQ飞车</value>
                <value>QQ炫舞</value>
                <value>穿越火线</value>
            </set>
        </property>
        <!--第三种  null注入-->
        <property name="jieW">
            <null/>
        </property>
        <!--第四种  property注入-->
        <property name="info">
            <props>
                <prop key="driver">4564546</prop>
                <prop key="url">hfafhafafafafaf</prop>
                <prop key="root">root</prop>
                <prop key="pwd">518340</prop>
            </props>
        </property>
    </bean>