且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Spring-boot:将默认值设置为可配置属性

更新时间:2022-04-06 10:03:01

检查property1是否属性在MyProperties类中使用@PostContruct设置。如果不是,您可以将其分配给另一个属性。

Check if property1 was set using a @PostContruct in your MyProperties class. If it wasn't you can assign it to another property.

@PostConstruct
    public void init() {
        if(property1==null) {
            property1 = //whatever you want
        }
    }