<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:myapp.properties"/>
</bean>
and use it in your beans:
<bean id="a" class="myapp.A">
<property name="str"><value>${myapp.somekey}</value></property>
</bean>
However, when you run your application you get the error:
Invalid bean definition with name 'a' defined in resource loaded
through SAX InputSource: Could not resolve placeholder
'myapp.somekey'.
I spent almost 3 hours trying to figure out. Urrrghhhh.
Finally, I understood why this happens and how to avoid it.
The Play! Spring module uses a GenericApplicationContext and
problematically adds a PropertyPlaceholderConfigurer to it, allowing
you to substitute place holders with values in your application.conf
file. (is this documented anywhere?)
Now, when Spring invokes
AbstractApplicationContext.invokeBeanFactoryPostProcessors() it
invokes Play's PropertyPlaceholderConfigurer, which tries to convert $
{myapp.somekey} as well.
Since it can't find ${myapp.somekey} in application.conf the exception
is thrown.
The way to "fool" the PropertyPlaceholderConfigurer Play! adds is to
override your applications place holder prefix and suffix.
This can be done in your application-context.xml file, for example:
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:myapp.properties"/>
<property name="placeholderPrefix"><value>#[</value></property>
<property name="placeholderSuffix"><value>]</value></property>
</bean>
<bean id="a" class="myapp.A">
<property name="str"><value>#[myapp.somekey]</value></property>
</bean>
Now your application can read properties from any properties file you
want.
Oded
> --
> You received this message because you are subscribed to the Google Groups "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
>
>