1
I am developing an API with Spring Boot, and I have 2 properties files for the development and production environments, How do I set the properties file of certain environment?
1
I am developing an API with Spring Boot, and I have 2 properties files for the development and production environments, How do I set the properties file of certain environment?
1
1. Add the profiles of dev and Prod in your file pom.xml
<profiles>
<profile>
<id>dev</id>
<properties>
<spring.profile>dev</spring.profile>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>prod</id>
<properties>
<spring.profile>prod</spring.profile>
</properties>
</profile>
</profiles>
2. Add the following line to your file application properties:
[email protected]@
3. Create two files that represent your dev and Prod
application-dev.properties
application-prod.properties
4. Execute the project according to the profile
dev: mvn clean compile spring-boot:run
Prod: mvn clean compile spring-boot:run -Pprod
On my Github you have a project with this setup. Links:
Browser other questions tagged java spring-mvc spring-boot
You are not signed in. Login or sign up in order to post.
Thanks, I did the same as the example, but when deploying with the command below " mvn clean spring-boot:run -Dspring.profiles.active=Prod ", it takes the development profile. 2017-10-10 14:39:00.464 INFO 5470 --- [ restartedMain] c.ernetwork.api.Apiernetworkapplication : The following profiles are active: dev Sera I forgot some detail?
– wanderwang
It worked, I ran this "mvn spring-boot:run -Drun.profiles=Prod" command. Thanks for the help
– wanderwang
@wanderwang, I’m glad it worked out! A while ago I had this same problem. hehe
– Wellington Costa