Manage for different environments for java application without spring boot

Manoj Mohan
Jun 20 · 1 min read

We wanted to manage different configurations like database URL, API keys for different environments. When we went for help with Google, all we saw was how to do it on spring boot applications. After a complete day of work, we were able to set it up. So, below are the steps

Our application was built on spring 4 and Java 1.8


import org.springframework.context.annotation.PropertySource;@PropertySource(value = “”)// Access value like belowdataSource.setUsername(environment.getRequiredProperty("jdbc.username"));


import org.springframework.context.annotation.PropertySources;
import org.springframework.context.annotation.PropertySource;
@PropertySources({@PropertySource(value = “”),@PropertySource(value=””, ignoreResourceNotFound=true),@PropertySource(value=””, ignoreResourceNotFound=true)})dataSource.setUsername(environment.getRequiredProperty("jdbc.username"));

Then what?

Add and to .gitignore. So that production and beta configurations will be out of VCS.

Manually create these configs in beta and prod environments. So, When application.*.properties exists these will override the

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade