Search code examples
spring-bootprofileapplication.properties

Spring Boot 1.3.8 @Profile and properties


I do use profiles in my Spring Boot application. In my application.properties I have this 3 entries:

spring.profiles.active=prod
key1=demo. ...
key1=prod. ...

Currently I have to uncomment the line depending on whether it is a demo or a productive release. Is there a better way of doing this using profiles of Spring Boot?


Solution

  • Yes, you can create property files with postfix of your profile name and dump profile specific properties there.

    For example,

    in your application-prod.properties this one will go key1=prod. ... in your application-demo.properties this one will go key1=demo. ...

    And while starting the server pass this java param -Dspring.profiles.active=<profilename> or set env variable SPRING_PROFILES_ACTIVE=<profile_name>