I currently have a Spring xml configuration (Spring 4) that load the properties file.
context.properties
my.app.service = myService my.app.other = ${my.app.service}/sample
Spring xml configuration
<bean id="contextProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="ignoreResourceNotFound" value="true" /> <property name="fileEncoding" value="UTF-8" /> <property name="locations"> <list> <value>classpath:context.properties</value> </list> </property> </bean> <bean id="placeholder" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="ignoreResourceNotFound" value="true" /> <property name="properties" ref="contextProperties" /> <property name="nullValue" value="@null" /> <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" /> </bean>
Bean that use properties
@Component public class MyComponent { @Value("${my.app.other}") private String others; }
This works fine, and the value of others MyService/sample is excluded. But when I try to replace this JavaConfig configuration, @Value in my component does not work like that. the value is not MyService/sample , but ${my.app.service}/sample .
@Configuration @PropertySource(name="contextProperties", ignoreResourceNotFound=true, value={"classpath:context.properties"}) public class PropertiesConfiguration { @Bean public static PropertyPlaceholderConfigurer placeholder() throws IOException { PropertyPlaceholderConfigurer placeholder = new PropertyPlaceholderConfigurer(); placeholder.setNullValue("@null"); placeholder.setSystemPropertiesMode(PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE); return placeholder; } }
Am I missing something in the conversion from xml to Javaconfig?
ps: I am also trying to create an instance of PropertySourcesPlaceholderConfigurer instead of PropertyPlaceholderConfigurer without any success.
java spring spring-java-config properties-file
herau
source share