Spring中注解分为2类

使用Bean

即是把已经在xml文件中配置好的Bean拿来用,完成属性、方法的组装;比如 @Autowired, @Resource,可以通过byTYPE(@Autowired)、byNAME(@Resource)的方式获取Bean;

注册Bean

@Component , @Repository , @Controller , @Service , @Configration这些注解都是把你要实例化的对象转化成一个Bean,放在IoC容器中,等你要用的时候,它会和上面的@Autowired , @Resource配合到一起,把对象、属性、方法完美组装。