0

Background : I don't want to hardcode properties in a java constant file, coz every time I want to change to one of the property_value, I have to build and deploy the entire code again. I don't even want to keep them in application.yaml/application.properties file, coz my properties are huge in numbers(100s). So, I have decided to maintain properties in a properties table in oracle DB.

I can think of two approaches :

  1. Read the property value as and when required by firing a sql query.
  2. Load all/part of the properties at the time of starting application and have global point of access by caching them.

As I need few of the properties in the beginning itself, I want to go with approach number 2.

I wanted to go for singleton bean, but this requires me to know all of the keys(property_names) in the beginning itself, and makes the singleton look ugly having 100s of member variables. Here I was planning to fire query by using pre-construct function of spring bean. The main problem here is the bean requires to be changed every time I add/delete properties from the properties table.

Another approach I could think of was to go with a Map<String,String> as both the property_name and property_value columns of my table are of VARCHAR type. But the question is how can I get global point of access to this map ?

Any better approaches much appreciated!

Many thanks in advance

crazy_code
  • 344
  • 3
  • 16

1 Answers1

0

If you deploy your app on web server you can take advantage of it. Many of web server supports changing configuration on the fly (using web console) such as JBoss EAP.

The other idea is to build your own properties lib. Create a function which read the data. I'd prefer using NoSQL database than RDBMS because of lightweight, great performance and scale very well. I wouldn't use caching unless it persisted somewhere and good on availability.

I've heard about Spring Cloud Config to externalize configuration but i never deep dive into it.

Some of us uses Apache Commons Configuration that support properties reload. Take a look at this thread.

  • Thanks for answering! I can't go for JBoss EAP as I can only use embedded jetty/tomcat in my app. Also, I can't use NoSQL db only for this specific requirement. Spring cloud config server comes with overhead of maintaining it (as a separate service) and is usually helpful when you want to externalize the configs of multiple microservices in a centralized place. – crazy_code May 21 '21 at 10:42