springboot读取配置文件值
依赖注入
1、非静态属性
@Configuration @ConfigurationProperties("flow") @Data @Accessors(chain = true) public class FlowConfig { /** * 账号 */ private String username;
@Configuration //放在类上
// Redis服务器地址 @Value("${spring.redis.host}") private String host;
2、静态属性
需要添加set方法,而且set方法不能为静态
@Configuration public class BIMUtils { private static String url; // 上传照片接口 private static String FILE_URL; //新增问题接口: private static String ADD_URL; private static String EDIT_URL; @Value("${bim.url}") public void setUrl(String url) { BIMUtils.url = url; FILE_URL=BIMUtils.url+"/api/v1/files"; ADD_URL=BIMUtils.url+"/api/v1/thirdpart/topics"; EDIT_URL=BIMUtils.url+"/api/v1/thirdpart/topics/"; }
private static RocketmqLogMapper rocketmqLogMapper; @Resource public void setRocketmqLogMapper(RocketmqLogMapper rocketmqLogMapper) { RocketMQUtil.rocketmqLogMapper = rocketmqLogMapper; }