-
Feb 6th, 2013, 05:29 PM
#1
Controlling data source for property injection (@Value)
Currently, @Value annotated fields retrieve their values from system properties at some point during Spring context initialization.
I would like to know if there was a way to either:
1) dictate where those values are retrieved (e.g., from someplace else other than system properties), or
2) if that's not possible, inject something into the Spring lifecycle such that I could read my properties from someplace else and then add them to the system properties.
For #2, we have a settings server defined in our Spring XML we would like to hit to retrieve these values. The key would be to have the settings server bean defined but prior to Spring processing the @Value annotations.
Any assistance will be welcome, thanks.
-
Feb 7th, 2013, 08:59 AM
#2
Yes. I use the PropertyPlaceholderConfigurer (http://static.springsource.org/sprin...onfigurer.html) to make values from a property file available.
also see http://www.javaworld.com/community/node/8309
-
Feb 7th, 2013, 10:12 AM
#3
Thanks for the reply. So, I'm a little confused. Are you suggesting I provide my own PropertyPlaceholderConfigurer? If so, I'm confused as to what method I would need to override to provide my values.
Please note that my properties will not be coming from a properties file, but rather a property server - but I assume this can be injected.
-
Feb 7th, 2013, 12:23 PM
#4
If I was in your shoes, I would look at the source for PropertyPlaceholderConfigurer and PropertyResourceConfigurer to see how I might extent/override/or reuse to create a bean that fetches the values from the property server and adds them to the context like reqular properties that one might pull from a .properties file.
Last edited by jasonparallel; Feb 7th, 2013 at 12:30 PM.
-
Feb 7th, 2013, 12:31 PM
#5
See this thread for how you could pipe jndi props into PropertyPlaceholderConfigurer
http://forum.springsource.org/showth...search-in-JNDI
I assume you could write something custom to push in as a location if you needed to
-
Feb 8th, 2013, 02:02 PM
#6
Yea, I'll need to allot some time to play around with this. Thanks.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules