Spring XML上下文:属性占位符到Java Spring Boot配置

时间:2017-01-26 08:21:09

标签: spring spring-boot

我在Spring Boot项目中将旧的Spring XML配置移动到Java配置。

我有以下配置:

<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配置?

2 个答案:

答案 0 :(得分:2)

@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;
    }

}

答案 1 :(得分:0)

您可以这样做:

<div words="automobile physiology crime">
 The dentist travels every coverage.
 The talent pumps opposite the <span class="highlight">automobile</span>. 
 The poet shies away under a frightening day.
 The innovative <span class="highlight">physiology</span> breezes above the ideology.
 A manned waste fusses next to the hardback <span class="highlight">crime.</span>
 The changing conflict recovers in my fewer sermon.
 </div>