Dav*_*mes 2 java spring dependency-injection spring-boot
在Spring Boot的源代码中,我对具有@Autowired注释和右手赋值的类字段感到困惑.
@Autowired
private ResourceProperties resourceProperties = new ResourceProperties();
Run Code Online (Sandbox Code Playgroud)
换句话说,此字段配置为字段注入,但也使用new运算符直接分配.实际分配给这个变量的是什么?
创建实例时,初始化表达式的值将分配给该字段.当AutowiredBeanPostProcessor处理该字段时,它将为其分配新值.
如果你希望在Spring的上下文之外运行相同的类,你可以编写这样的代码.
| 归档时间: |
|
| 查看次数: |
212 次 |
| 最近记录: |