1. 程式人生 > 實用技巧 >Spring xml注入 以及 xml配置

Spring xml注入 以及 xml配置

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>