- 实际中很少会使用自动装配的方式,存在缺陷
- ByName使用反射原理赋值
- ByType方式存在多个该类型的bean则会报错,找不到唯一的装配bean
<?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:util="http://www.springframework.org/schema/util"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">
<bean id="personautow" class="com.hgh.spring.helloworld.PersonNew"
p:age="12"
p:city="shangsi"
p:name="String"
autowire="byName"
>
</bean>
<bean name="car" class="com.hgh.spring.helloworld.Car">
<property name="company" value="benchi"></property>
<property name="price" value="5000000"></property>
<property name="maxSpice" value="300"></property>
</bean>
</beans>