I don't seem to have access to properties through PropertyPlaceholderConfigurer. I'm working with spring-1.2.4.jar and from the example in chapter 8 of Better, Faster, Lighter Java. (With some modifications as, for example, XmlBeanFactory wouldn't take an InputStream.)
(While I've looked at a fair number of examples and articles, this is the first time I've tried to write anything using Spring. So please be gentle.)
I have:
Then this code prints ${USER_NAME} rather than wsmoak:Code:daoContext.xml: <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location"> <value>classpath:u2.properties</value> </property> </bean> <bean id="uniSession" class="net.wsmoak.dao.spring.UniSessionBean"> <property name="userName"><value>${USER_NAME}</value></property> </bean> u2.properties: USER_NAME=wsmoak
So it is "working" in that it's creating the UniSessionBean instance and calling setUserName, but it's not using the property value.Code:ClassPathResource resource = new ClassPathResource( "daoContext.xml" ); XmlBeanFactory beanFactory = new XmlBeanFactory( resource ); UniSessionBean uSession = (UniSessionBean) beanFactory.getBean("uniSession"); System.out.println( uSession.getUserName() );
The u2.properties file is sitting in target/classes right beside daoContext.xml, so if it can see one, it should be able to see the other.
What am I missing? Thanks in advance for your help.
--
Wendy



Reply With Quote