两种方式
- @Component + @Autowired
需要引用的spring容器中的bean,加入spring - @component
配置类中注入 - @Autowired - 以方法的形式定义Bean
@Bean
private XXX getXXX(){
return new XXX()
}
通过调用方法引入。
本文介绍Spring框架中Bean的两种定义方式:使用@Component注解和在配置类中以@Bean方法定义。并通过@Autowired进行依赖注入。
两种方式
842

被折叠的 条评论
为什么被折叠?