Reputation: 31
I am using a Pivotal Cloud foundry with different testing environments (test, QA, UAT, PROD) Spring boot application I have created multiple properties files(Each pointing to different db) like
application-dev.properties
application-test.properties
application-qa.properties
application-uat.properties
application-prod.properties
if it is in local i am running by seting -Dspring.progiles.active=test/qa/uat/prod
mvn clean compile springboot:run -Dspring.progiles.active=test
How can I make it customize my application to use the specific properties file based on the environment in the cloud?
What all the configurations do I need to change? Below is my application.properties
file.
spring.profiles.active=test
spring.datasource.url=
spring.datasource.username=
spring.datasource.password=
spring.datasource.driver-class =org.hibernate.dialect.TeradataDialect
spring.jpa.database-platform=org.hibernate.dialect.TeradataDialect
spring.jpa.show-sql = true
spring.jpa.hibernate.ddl-auto = none
spring.jpa.properties.hibernate.default_schema=
spring.jpa.properties.hibernate.dialect= org.hibernate.dialect.TeradataDialect
server.port=9090
logging.level.org.springframework.web=INFO
logging.level.org.hibernate=INFO
logging.file=myapplication.log
or do I need to change whenever I move to higher environments?
Thanks in advance.
Upvotes: 2
Views: 594
Reputation: 349
You can have one applicaiton.yml
file for all of your environments and separate environment-specific manifest file. Use spring profile feature to add environment-specific properties. Spring will auto pick the properties based on the active environment profile and manifest file.
Example application.yml can have
spring:
profiles: default
username: xyz
spring:
profiles: development
username: abc
And in an environment-specific manifest file you can have:
env:
SPRING_PROFILES_ACTIVE: development
Upvotes: 2
Reputation: 1708
You've to move all your property files to GIT by leveraging Spring Cloud Config Server. From your application, use bootstrap.yml file to connect with Config Server and you'll be providing the environment name like prod, dev, qa.
Upvotes: 0