java - @Configuration 类中 @Bean 和 @PostConstruct 的 Spring 调用顺序
问题描述
我有一个像这样设置的配置类:
@Configuration
public class MyConfigClass {
private String field1;
@PostConstruct
public void init() {
field1 = < system property >
}
@Bean
MyService myService() {
// initialize MyService and use field1
}
}
我想知道 init() 方法是否总是在 myService() 方法之前运行,因为 myService() 方法依赖于 init 运行来设置某些系统属性的值。
我知道我可以在 myService() 中初始化 field1,但我对在上面显示的确切场景中会发生什么感兴趣。
解决方案
推荐阅读
- python-3.x - 无法在 ubuntu 18.04 上安装 psycopg2
- javascript - Django,在 HTML 模板中,我在 id =snackbar 中使用了 jinja2,但是当我点击按钮时,弹出窗口只是显示但没有 {{MSG}}
- python - 如何使用 spark 对动作进行会话化?
- json - 带有 Json 文件的 Asp.NET Core 根目录
- image - 社区版海量上传Akeneo图片
- docker - Docker 本地与远程缓存(--cache-from)
- python - 在 Python 3 中,如何从字符串中删除所有非 UTF8 字符?
- c# - Winforms (.NET Core 3) 是否支持所有 .NET Framework 控件
- flutter - 如何将输入保存在列表共享首选项中
- mysql - 尝试执行存储过程时出现错误 1064