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:p="http://www.springframework.org/schema/p" xmlns:c="http://www.springframework.org/schema/c" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd"> <!-- a service object; we will be profiling its methods --> <bean id="user" class="com.stone.cn.pojo.User"></bean> <bean id="userDaoImpl" class="com.stone.cn.dao.impl.UserDaoImpl"></bean> <bean id="userDaoMysql" class="com.stone.cn.dao.impl.UserDaoMysql"></bean> <bean id="userDaoOracle" class="com.stone.cn.dao.impl.UserDaoOracle"></bean> <bean id="userServiceImpl" class="com.stone.cn.service.impl.UserServiceImpl"> <property name="userDao" ref="userDaoMysql"></property> </bean> <!-- this switches on the load-time weaving --> <!--<context:load-time-weaver/>--> </beans>
//不同类型的对象值注入格式,单个string name value 对象 name ref 数组array value
<bean id="moreComplexObject" class="example.ComplexObject"> <!-- results in a setAdminEmails(java.util.Properties) call --> <property name="adminEmails"> <props> <prop key="administrator">administrator@example.org</prop> <prop key="support">support@example.org</prop> <prop key="development">development@example.org</prop> </props> </property> <!-- results in a setSomeList(java.util.List) call --> <property name="someList"> <list> <value>a list element followed by a reference</value> <ref bean="myDataSource" /> </list> </property> <!-- results in a setSomeMap(java.util.Map) call --> <property name="someMap"> <map> <entry key="an entry" value="just some string"/> <entry key ="a ref" value-ref="myDataSource"/> </map> </property> <!-- results in a setSomeSet(java.util.Set) call --> <property name="someSet"> <set> <value>just some string</value> <ref bean="myDataSource" /> </set> </property> </bean>