【发布时间】:2020-06-22 05:36:44
【问题描述】:
我有几个属性文件(application.properties),其中包含类路径下的自定义和弹簧配置,我想根据系统变量加载这些属性。
我使用PropertySourcesPlaceholderConfigurer 加载如下属性。
@Bean
public PropertySourcesPlaceholderConfigurer loadResources() {
PropertySourcesPlaceholderConfigurer resourceConfigurer = new PropertySourcesPlaceholderConfigurer();
resourceConfigurer.setLocations(new ClassPathResource("file1"), new ClassPathResource("file2"));
return resourceConfigurer ;
}
但它未能覆盖 spring 配置(在 application.properties 中添加的 spring 配置),我想在 spring 选择 application.properties 文件后覆盖这些文件。 想法是以编程方式覆盖弹簧配置。 如何做到这一点?
【问题讨论】:
-
为什么?这只会向应用程序添加额外的处理,实际上不会覆盖任何东西(它甚至可能会破坏 Spring Boot 处理)。使用
--spring.config.location或--spring.config-additional-location运行应用程序,而不是尝试这样做。请参阅the documentation 了解如何加载其他文件。
标签: spring-boot