Juan Reina Pascual Juan Reina Pascual - 3 months ago 9
Java Question

Rewriting spring context from xml to java

I'm rewriting my Spring context from XML to Java class, but this bean below I don't know. Can anyone help me? I'm using Spring Boot.

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="order" value="10"/>
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property
name="properties" ref="externalConfigProperties">
</property>
</bean>

Answer

Try this:

@Configuration
public class Config {

    @Autowired Properties externalConfigProperties;

    @Bean
    PropertyPlaceholderConfigurer configurer(){
        PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
        configurer.setSystemPropertiesModeName("SYSTEM_PROPERTIES_MODE_OVERRIDE");
        configurer.setOrder(10);
        configurer.setIgnoreUnresolvablePlaceholders(true);
        configurer.setProperties(externalConfigProperties);
        return configurer;
    }

}
Comments