首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring上下文: Java信任的属性占位符

Spring上下文: Java信任的属性占位符
EN

Stack Overflow用户
提问于 2017-01-26 08:21:08
回答 2查看 3.3K关注 0票数 0

我正在将我以前的Spring配置转移到Java,并在Spring项目上透露了这一点。

我有以下配置:

代码语言:javascript
复制
<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配置?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-01-26 08:42:05

代码语言:javascript
复制
@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;
    }

}
票数 3
EN

Stack Overflow用户

发布于 2017-01-26 08:41:34

你可以这样做:

代码语言:javascript
复制
@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);
}

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41869312

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档