java - Spring from scratch - Bug on context:property-placeholder -
i'm doing test on very, simple application using spring.
my app have have one bean , i'm injecting simple string class , printing value. so far working.
what need:
i want string configuration file, create file inside /src/main/resource
what did:
1) on application-context.xml add:
<context:property-placeholder location="classpath:myconfigfile.properties" />
2) on application-context.xml change simple string use ${name_test}:
<bean id="hello" class="com.dummy.sayhello"> <property name="name" value="${name_test}" /> </bean>
3) double check myconfigfile.properties , contains "name_test=jacktheripper"
4) output not 'translating' value config file, have output when run app:
hello ${name_test}
and i'm stuck here, clue, tips???
just fyi
- i use this tutorial tests, maybe help.
- i add log4j maven dependencies , log4j config file , works fine! spring , log4j finding files inside "src/main/resource"
- i'm using maven, , run app, i'm using:
mvn clean compile exec:java
solution explanation:
the root cause how getting application-context.xml on java class.
i doing:
beanfactory factory = new xmlbeanfactory(new classpathresource("application-context.xml"));
and after post change to:
applicationcontext context = new classpathxmlapplicationcontext("application-context.xml");
- a place understand , read here
- thanks help!
the problem can imagine here use beanfactory
instead of applicationcontext
. compared applicationcontext
, beanfactory
misses advanced features including automatic registration of postprocessors, necessary <context:property-placeholder>
.
Comments
Post a Comment