java - 堆叠@Bean 和@Autowired 注解
问题描述
我正在尝试理解以下代码
@Bean
@ConditionalOnMissingBean(name = "monitor")
@ConditionalOnBean(name={"identity"})
@Autowired
public MyObject myObject(@Qualifier("identity") Identity identity) {
return new MyObject(clientFactory);
}
@Autowired 的用途是什么?
在我看来,这似乎是多余的。猜测作者可能认为它需要支持身份注入。但是,AFAIK,@Bean 会这样做。
- - 编辑 - -
可能需要提一下,我之前看到的示例在 @Configuration 类中。
@Bean
public AnotherObject anotherObject(Environment env) {
return new AnotherObject(env);
}
解决方案
推荐阅读
- reactjs - mapStateToProps 后 Props 仍然为空
- javascript - 如何从由句号、升级或问号结尾的句子组成的文本中忽略 .com .net 或 .org 成句子数组?
- material-ui - 使用 Ag-Grid 自定义单元格编辑器和 withStyles 在 Material UI 中生成高阶组件
- azure-devops - 在 Azure DevOps 中版本发布管道的更好方法(更像 git)?
- sql - 优化这块存储过程
- git - 无法推送到 Git - 一直要求我验证电子邮件
- postgresql - 避免在嵌套 SQL 查询中计算空值
- python - 在 django 中手动设计处理 inlineformset_factory 的模板的问题
- elasticsearch - How to filter logs based on severity in fluentd and send it to 2 different logging systems
- javascript - 更新 for 循环内的 Javascript 对象属性