Added test using custom properties file with util:properties and dereferenced with @Value("#{...}")

This commit is contained in:
Chris Beams 2009-03-30 17:17:44 +00:00
parent ea37cdc006
commit 1b13d8fadf
3 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util">
<context:annotation-config/>
<util:properties id="myProps" location="classpath:org/springframework/context/annotation/configuration/AutowiredConfigurationTests-custom.properties"/>
<bean class="org.springframework.context.annotation.configuration.AutowiredConfigurationTests$PropertiesConfig"/>
</beans>

View File

@ -118,4 +118,29 @@ public class AutowiredConfigurationTests {
return new TestBean(name);
}
}
@Test
public void testCustomProperties() {
ClassPathXmlApplicationContext factory = new ClassPathXmlApplicationContext(
"AutowiredConfigurationTests-custom.xml", AutowiredConfigurationTests.class);
TestBean testBean = factory.getBean("testBean", TestBean.class);
assertThat(testBean.getName(), equalTo("localhost"));
}
@Configuration
static class PropertiesConfig {
private String hostname;
@Value("#{myProps.hostname}")
public void setHostname(String hostname) {
this.hostname = hostname;
}
@Bean
public TestBean testBean() {
return new TestBean(hostname);
}
}
}