美文网首页
Spring中Bean及@Bean

Spring中Bean及@Bean

作者: shaolin79 | 来源:发表于2018-08-16 15:35 被阅读10次

注解分为两类:

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

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

@Bean是啥?

@Bean 用在方法上,告诉Spring容器,你可以从下面这个方法中拿到一个Bean

相关文章

网友评论

      本文标题:Spring中Bean及@Bean

      本文链接:https://www.haomeiwen.com/subject/erkobftx.html