spring自带注解:
@Autowired、@Qualifier、@Value、@Primary、@Required、@Component、@Repository、@Service、@Controller
注解关系:
(1) @Autowired =@Resource
(2)@Component=@Repository=@Service=@Controller
@Autowired注解:实现自动装配。
1.在 spring xml 配置文件中需要注入如下两个类:
<beans>
<bean id="testA" class="..../TestA" />
<bean id="testUtil" class="..../TestUtil" />
</beans>
2.若想要在 testUtil 类中装配 testA 类,则可以在 testUtil 类中使用@Autowired注解;
如果想将 TestA 注入到 TestUtil 中,代码如下:
public class TestUtil{
@Autowired
private Test testA;
.......
}
简单来说,自动装配就是让Spring自动满足bean依赖的一种方法,在满足依赖的过程中,会在Spring应用上下文中寻找匹配某个bean需求的其他bean。