Spring中@Bean和@Component批注之间的区别。
Spring支持多种类型的注释,例如@Component,@Controller,@service@Repository和@Bean。所有这些都可以在org.springframework.stereotype包下找到。
当我们的应用程序中的类使用上述任何注释进行注释时,则在项目启动时进行spring扫描(使用@componentScan),然后将每个类注入到IOC容器中。@ComponentScan要做的另一件事是运行带有@Bean的方法,并将返回对象作为Bean恢复到Ioc容器。
@Configuration注释即可工作
@Component的示例
@Component
public class Pizza{
........
}@Bean的示例
@Configuration
class AppConfiguration{
@Bean
public User getUse(){
return new User();
}
}热门推荐
10 新人红包祝福语简短精辟
11 幼师给毕业祝福语简短
12 生日高考祝福语妹妹简短
13 下飞机祝福语简短英文
14 元宵发客户祝福语简短
15 爸妈金婚文案祝福语简短
16 新郎朋友红包祝福语简短
17 虎年五一祝福语大全简短
18 出阁宴祝福语姐姐简短