DongHoon  Kim
DongHoon Kim

Reputation: 386

What is best practice management properties for me?

What can I do for best practice management properties?

  1. I want to set different properties each deployed environment.
  2. Some of my developer cannot detect my real server properties.
  3. I want to build project using same command (using maven. not want to -P dev, -P production options)
  4. I don't want to too many source code to load my properties.(like implements db access)
  5. Can be continue my service without restart when some properties has been changed.

My service developed using spring-web.

Upvotes: 0

Views: 66

Answers (1)

Essex Boy
Essex Boy

Reputation: 7950

You have 2 issues:

1) How to have your properties outside of the war file, I would suggest you do the following:

@PropertySource(value={"classpath:/config.properties", "file:${configRoot}/config.properties"}, ignoreResourceNotFound = true)

Then when you start your app you can specify configRoot as a system property to the JVM i.e -DconfigRoot=/var/config. You can then specify a default config which will be pulled from inside the war. Using the ignoreResourceNotFound if the file:${configRoot}/config.properties"} can not be found the first one will be used. i.e. you can have a default inside the war and override it at runtime with the JVM system parameter.

2) How to automatically refresh

Look at this answer to tell spring to refresh it's properties on a schedule:

Upvotes: 1

Related Questions