在Spring Boot中,注入Bean的方法有以下几种:
@Autowired
private BeanName beanName;
@Resource
private BeanName beanName;
@Configuration
public class AppConfig {
@Bean
public BeanName beanName() {
return new BeanName();
}
}
@Service
public class MyService {
private BeanName beanName;
@Autowired
public MyService(BeanName beanName) {
this.beanName = beanName;
}
}
@Autowired
@Qualifier("beanName1")
private BeanName beanName;
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: springboot怎么调用第三方接口获取文件流