我正在将我以前的Spring配置转移到Java,并在Spring项目上透露了这一点。
我有以下配置:
<context:property-placeholder location="file:${catalina.home}/conf/patient-api.application.properties" order="1" ignore-resource-not-found="true" ignore-unresolvable="true"/>
<context:property-placeholder location="classpath:application.properties" order="2" />如何将其转换为适当的Java配置?
发布于 2017-01-26 08:42:05
@Configuration
@PropertySource(value="file:${catalina.home}/conf/patient-api.application.properties", ignoreResourceNotFound = true)
@PropertySource("classpath:application.properties")
public class AppConfig{
@Bean
public PropertyPlaceholderConfigurer placeholderConfigurer(){
PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
configurer.setIgnoreUnresolvablePlaceholders(true);
return configurer;
}
}发布于 2017-01-26 08:41:34
你可以这样做:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
ConfigurableApplicationContext applicationContext = new SpringApplicationBuilder(Application.class)
.properties(
"spring.config.name:patient-api.application,application",
"spring.config.location:classpath:/,file:${catalina.home}/conf/")
.build().run(args);
}
}https://stackoverflow.com/questions/41869312
复制相似问题