知识要点
<bean id="k" class="dd.K"></bean>
<bean id="mSub" class="dd.KSub"></bean>
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
@Autowired
public void setmSub(KSub mSub) {
this.mSub = mSub;
}
package dd;
import org.springframework.beans.factory.annotation.Autowired;
public class K {
private KSub mSub;
public KSub getmSub() {
return mSub;
}
@Autowired
public void setmSub(KSub mSub) {
this.mSub = mSub;
}
public void print() {
mSub.print();
}
}
package dd;
public class KSub {
public void print() {
System.out.println("KSub print");
}
}
<?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-3.0.xsd">
<bean id="k" class="dd.K"></bean>
<bean id="mSub" class="dd.KSub"></bean>
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
</beans>
package dd;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class T {
public static void main(String[] args) {
//Spring @Autowired 注释
System.out.println("Spring @Autowired 注释");
K k = (K)context.getBean("k");
k.print();
}
}