Spring Boot 注入外部配置到应用内部的静态变量
程序员文章站
2022-04-04 09:51:42
属性配置类 StaticProperties.class Spring Boot 配置提示 resources/META-INF/spring-configuration-metadata.json Spring Boot 配置 application.properties 至此,即可在 Sprin ......
属性配置类 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
上一篇: PHP7.27: connect mysql 5.7
下一篇: 【Python3爬虫】12306爬虫