重点 设置静态属性必须添加非静态set方法 不然会读取配置文件失败 还有就是 prefix只支持小写
配置文件项如下
配置文件
package com.mingx.drone.config; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Configuration; /** * @Description: 配置文件全部变量初始化 * @Author: gch * @Date: 2023/11/9 14:11 */ public class ApplicationProperties { @Data @ConfigurationProperties(prefix = "uap") @Configuration public static class UapUtilConfig { public static String contextPath; public static String productCenterDepartId; public static String buildDepartId; public void setContextPath(String contextPath) { UapUtilConfig.contextPath = contextPath; } public void setProductCenterDepartId(String productCenterDepartId) { UapUtilConfig.productCenterDepartId = productCenterDepartId; } public void setBuildDepartId(String buildDepartId) { UapUtilConfig.buildDepartId = buildDepartId; } } @Data @ConfigurationProperties(prefix = "system.ordersys") @Configuration public static class OrderSysConfig { public static String url; public static String token; public void setUrl(String url) { OrderSysConfig.url = url; } public void setToken(String token) { OrderSysConfig.token = token; } } }
添加测试配置
启动项目 运行效果:
标签:String,配置文件,void,ConfigurationProperties,static,public From: https://www.cnblogs.com/guanxiaohe/p/17821700.html