Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading application configuration properties from database in spring based application using java based configuration

Tags:

java

spring

Its better to store the configuration properties in a database table so that it can be managed easily for different environments. The approach to store and retrieve the configuration properties from database table in xml based configuration is like below :

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
   <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
   <property name="properties">
      <bean class="org.apache.commons.configuration.ConfigurationConverter" factory-method="getProperties">
         <constructor-arg>
            <bean class="org.apache.commons.configuration.DatabaseConfiguration">
               <constructor-arg>
                  <ref bean="dbDataSource" />
               </constructor-arg>
               <constructor-arg value="DOMAIN_CONFIG" />
               <!-- DB Table -->
               <constructor-arg value="CONFIG_NAME" />
               <!-- DB Key Column -->
               <constructor-arg value="CONFIG_VALUE" />
               <!-- DB Value Column -->
            </bean>
         </constructor-arg>
      </bean>
   </property>
</bean>

But the same thing i'm trying to achieve using java based configuration but no luck. Can anyone please help me.

like image 340
java developer Avatar asked May 06 '26 08:05

java developer


1 Answers

I found answer for my question.

Thanks to this post : https://gist.github.com/jeffsheets/8ab5f3aeb74787bdb051 This exactly suits to my problem. Thanks.!

like image 153
java developer Avatar answered May 07 '26 21:05

java developer