Browse Source

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

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@874 50f2f4bb-b051-0410-bef5-90022cba6387
pull/1/head
Chris Beams 17 years ago
parent
commit
532426a10d
  1. 3
      org.springframework.context/src/test/java/org/springframework/context/annotation/configuration/AutowiredConfigurationTests-custom.properties
  2. 16
      org.springframework.context/src/test/java/org/springframework/context/annotation/configuration/AutowiredConfigurationTests-custom.xml
  3. 25
      org.springframework.context/src/test/java/org/springframework/context/annotation/configuration/AutowiredConfigurationTests.java

3
org.springframework.context/src/test/java/org/springframework/context/annotation/configuration/AutowiredConfigurationTests-custom.properties

@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
hostname=localhost
foo=a
bar=b

16
org.springframework.context/src/test/java/org/springframework/context/annotation/configuration/AutowiredConfigurationTests-custom.xml

@ -0,0 +1,16 @@ @@ -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>

25
org.springframework.context/src/test/java/org/springframework/context/annotation/configuration/AutowiredConfigurationTests.java

@ -118,4 +118,29 @@ public class AutowiredConfigurationTests { @@ -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…
Cancel
Save