[Spring]@Autowired 的使用
<beans xmlns="http://www.springframework.org/schema/beans"
?xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
? xmlns:context="http://www.springframework.org/schema/context"
?xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
?http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
?<context:annotation-config></context:annotation-config>
?<bean id="auto123"? value="Jordan"></property>
?</bean>
?<bean id="auto"? autowire-candidate="false">
??<property name="name1" value="Crystal"></property>
?</bean>
?<bean id="autowire1" >
??<property name="helloWord" value="Michael"></property>
?</bean>
?
</beans>
2.AutoWireBean2
package org.michael.spring.demo.autowire;
import org.springframework.beans.factory.annotation.Autowired;
public class AutoWireBean2 {
?
?private String helloWord;?
?@Autowired
?private AutoWireBean auto;
?public String getHelloWord() {
??return helloWord;
?}
?public void setHelloWord(String helloWord) {
??this.helloWord = helloWord;
?}
?public AutoWireBean getAuto() {
??return auto;
?}
?
}
注意,这里的auto可以不用写set方法