Added test using custom properties file with util:properties and dereferenced with @Value("#{...}")
This commit is contained in:
parent
ea37cdc006
commit
1b13d8fadf
|
|
@ -0,0 +1,3 @@
|
|||
hostname=localhost
|
||||
foo=a
|
||||
bar=b
|
||||
|
|
@ -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>
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue