Spring完成自动装配,两种方式
default-autowire="byName"
default-autowire="byName"
default-autowire="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"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd" default-autowire="byName">
<!--
<bean id="bean2" class="com.bjpowernode.spring.Bean2">
<property name="bean3" ref="bean3"/>
<property name="bean4">
<ref bean="bean4"/>
</property>
<property name="bean5" ref="bean5"/>
</bean>
<bean id="bean3" class="com.bjpowernode.spring.Bean3">
<property name="id" value="100"/>
<property name="name" value="zhangsan"/>
<property name="sex" value="nan"/>
</bean>
<bean id="bean4" class="com.bjpowernode.spring.Bean4">
<property name="id" value="100"/>
<property name="name" value="zhangsan"/>
<property name="sex" value="nan"/>
<property name="age">
<value>90</value>
</property>
</bean>
<bean id="bean5" class="com.bjpowernode.spring.Bean5">
<property name="password" value="123"/>
</bean>
-->
<!--
<bean id="bean2" class="com.bjpowernode.spring.Bean2">
<property name="bean3" ref="bean3"/>
<property name="bean4">
<ref bean="bean4"/>
</property>
<property name="bean5" ref="bean5"/>
</bean>
<bean id="AbstractBean" abstract="true">
<property name="id" value="100"/>
<property name="name" value="zhangsan"/>
<property name="sex" value="nan"/>
</bean>
<bean id="bean3" class="com.bjpowernode.spring.Bean3" parent="AbstractBean"/>
<bean id="bean4" class="com.bjpowernode.spring.Bean4" parent="AbstractBean">
<property name="age">
<value>90</value>
</property>
</bean>
<bean id="bean5" class="com.bjpowernode.spring.Bean5">
<property name="password" value="123"/>
</bean>
-->
<bean id="bean2" class="com.bjpowernode.spring.Bean2">
</bean>
<bean id="AbstractBean" abstract="true">
<property name="id" value="100"/>
<property name="name" value="zhangsan"/>
<property name="sex" value="nan"/>
</bean>
<bean id="bean3" class="com.bjpowernode.spring.Bean3" parent="AbstractBean"/>
<bean id="bean4" class="com.bjpowernode.spring.Bean4" parent="AbstractBean">
<property name="age">
<value>90</value>
</property>
</bean>
<bean id="bean5" class="com.bjpowernode.spring.Bean5">
<property name="password" value="123"/>
</bean>
</beans>