【问题标题】:Spring Boot : PropertySourcesPlaceholderConfigurer is not loading system propertiesSpring Boot:PropertySourcesPlaceholderConfigurer 未加载系统属性
【发布时间】:2016-04-24 07:28:15
【问题描述】:

我有一个 Spring Boot 应用程序如下:

@SpringBootApplication
@PropertySource(ignoreResourceNotFound=true,value={"classpath:application.properties","classpath:util-${spring.profiles.active}.properties"})
@ComponentScan("com.jmarts")
@EnableTransactionManagement
public class Application extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Override
    protected SpringApplicationBuilderconfigure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    } 
}
  • 我正在使用 spring 配置文件并根据活动配置文件加载正确的环境特定文件:utils-local.properties、utils-dev.properties 等...
  • 当通过 application.properties (spring) 设置配置文件时,例如spring.profiles.active=local 一切正常,加载了正确的文件 (utils-local.properties)。
  • 通过 -D (gradle bootRun -Dspring.profiles.active=local) 提供配置文件不会加载配置文件。我能够验证系统属性是否已通过(打印 systemProperties)

如果没有配置,我假设 spring boot 将注册一个 PropertySourcesPlaceholderConfigurer。

【问题讨论】:

    标签: gradle spring-boot


    【解决方案1】:

    spring boot 正式支持profile-specific properties using the naming convention application-{profile}.properties.
    所以你可以删除“classpath:util-${spring.profiles.active}.properties”并在类路径中添加application-local.properties、application-dev.properties等。

    【讨论】:

      猜你喜欢
      • 2011-02-16
      • 1970-01-01
      • 1970-01-01
      • 2016-06-01
      • 2019-10-18
      • 1970-01-01
      • 2016-08-09
      • 2014-04-08
      • 2018-06-25
      相关资源
      最近更新 更多