属性配置类 StaticProperties.class

@Component
public class StaticProperties {

    public static String CUSTOM_NAME;

    @Value("${custom.name}")
    public void setCustomName(String customName) {
        CUSTOM_NAME = customName;
    }

}

Spring Boot 配置提示 resources/META-INF/spring-configuration-metadata.json

{
  "properties": [
    {
      "name": "custom.name",
      "type": "java.lang.String",
      "sourceType": "com.anoyi.xxx.config.StaticProperties"
    }
  ]
}

Spring Boot 配置 application.properties

custom.name=anoyi

至此,即可在 Spring Boot 全局任意引用 StaticProperties.CUSTOM_NAME

版权声明:本文为yahu原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/yahu/p/9303142.html