Spring 【自动装配】
<!-- autowire,自动装配 --> <bean id="autowire" class="autowire.AutoWire" autowire="byName"> <!-- <property name="greet" ref="gs"/> --> </bean>
AutoWire:自动装配
byName:按照bean的属性名自动装配,找不到装不上,不可能多个(id唯一).通过set方法装配
byType:寻找和属性类型相同的bean,找不到装不上,找到多个抛异常.
constructor:查找和bean的构造参数一致的一个或多个bean,若找不到或找到多个,抛异常。按照参数的类型装配。
注解方式:
@Autowired public void setGreet(GreetingService greet) { this.greet = greet; }
<!-- 自动装配【注解】bean后处理器,通过@AutoWire --> <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" />