spring-boot - 来自外部属性文件的弹簧组配置文件
问题描述
我正在从外部文件设置我的数据库属性,并尝试对活动配置文件执行相同的操作,但没有任何运气。
如果尝试在 app.propertiesspring.config.location= C:\\run\\secrets\\test
中:但这不起作用。
在我尝试过读取数据库属性的同一个配置文件中:
@Component
@Configuration
@PropertySource(value={"file:/run/secrets/file.properties"}, ignoreResourceNotFound = true)
public class AppProperties {
@Resource
private Environment env;
@Bean
public Properties props(){
Properties props = new Properties();
props.setProperty("spring.profiles.default", env.getRequiredProperty("spring.profiles.active"));
//props.put("spring.profiles.active", env.getRequiredProperty("spring.profiles.active"));
return props;
}
}
在我的外部文件中,我已经尝试
spring.profiles.active=dev
过spring.profiles.default=dev
似乎没有任何效果。
解决方案
如果我理解正确,您的文件在 C 盘上。
所以,在windows中,外部文件路径应该是这样的:
@PropertySource(value={"file:///C:/run/secrets/file.properties"}, ignoreResourceNotFound = true)
推荐阅读
- python - pandas/stockstats 类型错误('NoneType' 对象不可下标)
- c++ - 获取未来几秒钟的 struct timeval
- sed - 替换以a开头的单词
- unity3d - Addforce 随帧率变化
- javascript - 我将如何允许用户使用按钮或把手向上或向下移动 div?
- c++ - 条件中的参数过多
- reactjs - React-Bootstrap 从 Form-Select 中获取价值
- swift - 将图像上传到 Firebase 存储后,图像大小会增加
- javascript - 如何让我的 MERN 应用程序在 heroku 上正确刷新?
- javascript - getElementById 没有在脚本中返回任何内容或问题?