Gradle Spring引导:PropertySourcesPlaceholderConfigurer未加载系统属性
我有一个Spring Boot应用程序,如下所示:Gradle Spring引导:PropertySourcesPlaceholderConfigurer未加载系统属性,gradle,spring-boot,Gradle,Spring Boot,我有一个Spring Boot应用程序,如下所示: @SpringBootApplication @PropertySource(ignoreResourceNotFound=true,value={"classpath:application.properties","classpath:util-${spring.profiles.active}.properties"}) @ComponentScan("com.jmarts") @EnableTransactionManagement p
@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 all效果很好,将加载正确的文件(utils local.properties)
- 通过-D(gradle bootRun-Dspring.profiles.active=local)提供概要文件不会加载概要文件。我能够验证是否传递了系统属性(打印系统属性)
如果未配置任何属性资源占位符配置器,我假设spring boot将注册一个属性资源占位符配置器。spring boot正式支持。
因此,您可以删除“classpath:util-${spring.profiles.active}.properties”,并在类路径中添加application-local.properties、application-dev.properties等