Spring boot 外部属性文件中的弹簧集配置文件
我正在从一个外部文件设置我的数据库属性,并试图对活动配置文件执行相同的操作,但没有任何运气 在app.properties中,如果尝试:Spring boot 外部属性文件中的弹簧集配置文件,spring-boot,spring-boot-configuration,Spring Boot,Spring Boot Configuration,我正在从一个外部文件设置我的数据库属性,并试图对活动配置文件执行相同的操作,但没有任何运气 在app.properties中,如果尝试:spring.config.location=C:\\run\\secrets\\test,但这不起作用 在读取数据库属性的同一配置文件中,我尝试了: @Component @Configuration @PropertySource(value={"file:/run/secrets/file.properties"}, ignoreRes
spring.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)