0

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?

quma
  • 5,233
  • 26
  • 80
  • 146

2 Answers2

0

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>

Yogesh Badke
  • 4,249
  • 2
  • 15
  • 23
0

This is how it can be achieved:

  1. Use a single application.properties and having values in following format:

    redis.host=${REDIS_HOST}
    redis.port=${REDIS_PORT}
    
  2. Now use different .yml files for dev, staging and prod environments, where each file has values related to specific environment. For example, dev.yml, staging.yml, prod.yml:

    // dev.yml
    REDIS_HOST=localhost
    REDIS_PORT=6379
    
    // staging.yml
    REDIS_HOST=staging-url
    REDIS_PORT=6576
    
    //prod.yml
    REDIS_HOST=produrl
    REDIS_PORT=5678
    
  3. Now, run the application with profile parameter being passed for different environments:

    -Dspring.profiles.active=dev
    
KayV
  • 12,987
  • 11
  • 98
  • 148
  • I also use spring boot 1.2.3 and it does not work with -Dspring.profiles.active=dev. Actually i dont know. – quma Sep 24 '18 at 21:20