Bill Gorder wrote:For what you are trying to do you should just use the @PropertySource annotation. Now I am assuming you are using a web application and that code snippet probably came out of an ApplicationInitializer class. That would be fine but unnecessary I think for your use case.
The thing I think your missing is the spring environment as in org.springframework.core.env.Environment. That is where you go to grab your properties.
Here is a stand alone application to illustrate but nothing changes for a web-app really.
Say you have a properties file called
Now lets say you have Config file that looks like this I like using Java based configuration. You can use the Java based configuration together with XML as well. If I were doing XML only i would probably just specify the location of my property file on the propertySourcesPlaceholderConfigurer directly.
Here is the main class
This would output the user.home directory followed by Hello World.
Does that help?
Bill Gorder wrote:Hi Mike,
What you have there with the mix of XML and Java config should work. What properties are not being resolved? Did you declare the PropertySourcesPlaceHolder bean as static, like in my example?
I modified the example to prove this works:
This prints out the same as before followed by 'bill'
If I was not going to use the mix (no @PropertySource annotation) you can load the properties file on the PropertySourcesPlaceholder bean.