Profile-Specific Application.Properties in Spring

In NixMash Spring Solr we want to use a specific application.properties file for each Spring Profile type. The dev profile will read its properties from application-dev.properties and prod profile from, you guessed it, application-prod.properties.

There are a number of ways to do this, some way more complicated than others. I think you’ll agree the approach we’re looking at here is pretty darn simple.

Here are our .properties files in the Eclipse Package Explorer.

Without further chatter, here’s how we’re assigning a unique .properties file to each Spring ProfileĀ in a Configuration class. We add a couple of static inner classes and annotate each as you see. Remember to make the class static and don’t leave out any of the three annotations.

We like simple…