【发布时间】: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