<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd ">
<!-- 将user对象交给spring容器管理 -->
<!-- 空参构造创建对象 -->
<!-- set方式注入 -->
<bean name="user" class="entity.User">
<property name="userName" value="Tom"></property>
<property name="userAge" value="18"></property>
<property name="userId" value="8"></property>
<property name="car" ref="car"></property>
</bean>
<bean name="car" class="entity.Car">
<property name="name" value="兰博基尼"></property>
<property name="color" value="红色"></property>
</bean>
<!-- =============== -->
<!-- 构造方法注入 -->
<bean name="user2" class="entity.User">
<constructor-arg name="userName" value="TO" ></constructor-arg>
<constructor-arg name="userAge" value="1"></constructor-arg>
<constructor-arg name="userId" value="9"></constructor-arg>
<constructor-arg name="car" ref="car"></constructor-arg>
</bean>
<!-- 复杂类型注入 -->
<bean name="user3" class="entity.User">
<!-- 给数组array注入值 -->
<property name="arr">
<array>
<value>tom</value>
<value>jerry</value>
<ref bean="car"/>
</array>
</property>
<!-- 给list注入值 -->
<property name="list">
<list>
<value>list1</value>
<value>list2</value>
<ref bean="car"/>
</list>
</property>
<property name="map">
<map>
<entry key="k" value="v"></entry>
<entry key="car" value-ref="car"></entry>
<entry key-ref="car" value-ref="user"></entry>
</map>
</property>
<property name="prop">
<props>
<prop key="pk">pkv</prop>
</props>
</property>
</bean>
</beans>
spring的各种注入格式