Reputation: 1227
I'm wondering if its possible to use the value in DB before properties file in PropertyPlaceholderConfigurer. So what I want to achieve is to load the properties file, and if any keys exist in the database, use that. Right now I don't know where to start, but I'm assuming that there is a method/class that I can override or interface that I need to implement.
Just mention the method/class/interface and I will gladly start from there. TIA
Upvotes: 2
Views: 7371
Reputation: 1312
Since you want to merge properties, you may want to implement InitializingBean on your target bean. Your hook will be the afterPropertiesSet method, where you can go about with your kung-fu.
BTW, Spring loads and overrides beans definitions in the order the container encounters it.
Upvotes: 1
Reputation: 16085
PropertyPlaceholderConfigurer has a "properties" property that can point to an object that retrieves the database values. See an example here: http://pure-essence.net/2011/02/10/spring-loading-properties-from-database-with-a-twist/
Also, you'll want to set "ignoreUnresolvablePlaceholders" to true on the bean that config that loads the properties from the database. That way you can add another PropertyPlaceholderConfigurer as a fallback to provide properties that are not found in the database.
Upvotes: 8