知识要点
@Required
public void setmSub(int mSub) {
this.mSub = mSub;
}
package dd;
import org.springframework.beans.factory.annotation.Required;
public class J {
private int mSub;
public int getmSub() {
return mSub;
}
@Required
public void setmSub(int mSub) {
this.mSub = mSub;
}
public void print() {
System.out.println("mSub:"+mSub);
}
}
package dd;
public class ESub {
public void print() {
System.out.println("ESub 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="j" class="dd.J">
<property name="mSub" value="5"/>
</bean>
</beans>
package dd;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class T {
public static void main(String[] args) {
// Spring @Required 注释
System.out.println("Spring @Required 注释");
J j = (J)context.getBean("j");
j.print();
}
}