对此的解决方案可能非常简单,但我不确定我缺少什么.这就是我拥有的,PropertyPlaceholderConfigurer
不会取代的${...}
.
/* ---- org/company/springtest/Test.java: ---- */ package org.company.springtest; import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.Resource; public class Test { public static void main( String... args ) { Resource res = new FileSystemResource("conf/xml/context2.xml"); XmlBeanFactory beanFactory = new XmlBeanFactory(res); TestApp app = (TestApp) beanFactory.getBean("testApp"); app.print(); } } /* ---- org/company/springtest/TestApp.java: ---- */ package org.company.springtest; import org.springframework.beans.factory.annotation.Required; public class TestApp { private String m_message; public void setMessage( String message ) { m_message = message; } public void print() { System.out.println(m_message); } } /* ---- conf/xml/context2.xml: ---- *//* ---- conf/xml/test.properties: ---- */ test.message=Hello world!
以下是运行Test时的输出:
Feb 17, 2009 11:23:06 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO: Loading XML bean definitions from file [C:\eclipse\workspace\SpringTest\conf\xml\context2.xml] ${test.message}
看起来配置器没有替换属性值......
也许尝试使用ApplicationContext
而不是BeanFactory
?