1.@Required 注解。必须要人为去配置属性值
setter方法是只要加上注解,必须在xml中配置具体的值。
2.@Autowired注解。提示spring,某个id需要去配置文件中查找就实例化。
3.@Qualifier 注解。
当一个类在xml中定义了多个id时,如果仅需要实例化其中一个可以用.@Qualifier。
<!-- Definition for student1 bean --> <bean id="student1" class="com.tutorialspoint.Student"> <property name="name" value="Zara" /> <property name="age" value="11"/> </bean> <!-- Definition for student2 bean --> <bean id="student2" class="com.tutorialspoint.Student"> <property name="name" value="Nuha" /> <property name="age" value="2"/> </bean>
@Autowired @Qualifier("student1") private Student student;
注意@Autowired自动装配标签要用上。