From 532426a10d6764cd40be88f85825d0b38544d9ec Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Mon, 30 Mar 2009 17:17:44 +0000 Subject: [PATCH] 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 --- ...owiredConfigurationTests-custom.properties | 3 +++ .../AutowiredConfigurationTests-custom.xml | 16 ++++++++++++ .../AutowiredConfigurationTests.java | 25 +++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 org.springframework.context/src/test/java/org/springframework/context/annotation/configuration/AutowiredConfigurationTests-custom.properties create mode 100644 org.springframework.context/src/test/java/org/springframework/context/annotation/configuration/AutowiredConfigurationTests-custom.xml diff --git a/org.springframework.context/src/test/java/org/springframework/context/annotation/configuration/AutowiredConfigurationTests-custom.properties b/org.springframework.context/src/test/java/org/springframework/context/annotation/configuration/AutowiredConfigurationTests-custom.properties new file mode 100644 index 00000000000..17a2bc67bcc --- /dev/null +++ b/org.springframework.context/src/test/java/org/springframework/context/annotation/configuration/AutowiredConfigurationTests-custom.properties @@ -0,0 +1,3 @@ +hostname=localhost +foo=a +bar=b \ No newline at end of file diff --git a/org.springframework.context/src/test/java/org/springframework/context/annotation/configuration/AutowiredConfigurationTests-custom.xml b/org.springframework.context/src/test/java/org/springframework/context/annotation/configuration/AutowiredConfigurationTests-custom.xml new file mode 100644 index 00000000000..e0c4ef6ea23 --- /dev/null +++ b/org.springframework.context/src/test/java/org/springframework/context/annotation/configuration/AutowiredConfigurationTests-custom.xml @@ -0,0 +1,16 @@ + + + + + + + + + + diff --git a/org.springframework.context/src/test/java/org/springframework/context/annotation/configuration/AutowiredConfigurationTests.java b/org.springframework.context/src/test/java/org/springframework/context/annotation/configuration/AutowiredConfigurationTests.java index cacb17f224c..68755bc06f9 100644 --- a/org.springframework.context/src/test/java/org/springframework/context/annotation/configuration/AutowiredConfigurationTests.java +++ b/org.springframework.context/src/test/java/org/springframework/context/annotation/configuration/AutowiredConfigurationTests.java @@ -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); + } + } }