什么是自动装配:
根据指定装配规则(属性名称或者属性类型),spring自动将匹配的属性值进行注入。
根据属性名称自动注入:
autowire属性常用两个值:
- byName根据属性名称注入,注入值bean的属性名称一样。
byType根据属性类型注入。
<?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.xsd"><bean id="emp" class="com.zcc.spring.pojo.Emp" autowire="byName"><!-- <property name="user" ref="user"/>--></bean><bean id="user" class="com.zcc.spring.pojo.User"><property name="id" value="10001111"/><property name="name" value="张三"/></bean><bean id="user1" class="com.zcc.spring.pojo.User"><property name="id" value="10002"/><property name="name" value="张三"/></bean></beans>
