I have developed a web application using spring boot. I have three resource folders in src/main/resources staging,qa,production which consists of application properties and logging configuration for the specific environment. Along with these folders I have application.properties and logging configuration in resources folder which I use it for dev environment. I want to package war file according to the environment using spring-boot-maven plugin. I am new to maven any help would be appreciated?
2 Answers
Convetion is application-{profileName}.properties
Point 10 and 11:
http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html
e.g application-test.properties
it overrides the application.properties
Make profile in pom.xml
Introduction to profiles: http://maven.apache.org/guides/introduction/introduction-to-profiles.html

- 1,978
- 1
- 19
- 33
-
It works for application.properties. What should I do for other configuration files(example logging). – Manu Aug 16 '16 at 09:12
-
Can you tell me more about this `logging configuration for the specific environment` ? Are you sure that you can not create variables in `application.properties` that will do the stuff and change them based on your needs? – Kamil Witkowski Aug 16 '16 at 09:20
-
log file paths will be different in each environment. We can create variables in application.properties files, but application.properties doesn't allow to completely configure log4j2, so I am using xml configuration files specific for each environment. What if I want to deploy war in external container, I couldn't pass active profiles information during deployment. Do you have any solution to pass only environment specific properties while packaging the war? – Manu Aug 16 '16 at 20:13
Rather than using Maven to add different folders to your classpath for each environment, you can use Spring profiles.
First of all create different application.properties for each environment, such as:
- application-staging.properties
- application-qa.properties
- application-production.properties
For the logging you can use the logging.config
property. So, in application-staging.properties you could use:
logging.config=classpath:logback-staging.xml
In the other properties files you can use different logging.config
properties.
Now just run your application with the spring.profiles.active
property.
However, an easier solution would be to use externalized configuration. Rather than having to rebuild each time you want to change configuration for a specific profile, you can externalize it by putting an application.properties file next to your JAR/WAR in the correct environment, rather than on your classpath. Spring boot will pick this up automatically.
Now you can also externalize your logging config by placing a logback.xml (or log4j2.xml, ...) file next to your JAR/WAR and just configure your (externalized) application properties with:
logging.config=file:logback.xml
This allows you to edit your configuration and logging without having to change your JAR/WAR.

- 41,995
- 13
- 95
- 133
-
While deploying in external tomcat container, I just add the war file to the webapps folder and restart the container. So, I have to add correct application.properties file while packaging the war. How can I achieve this during packaging time. >>>> Just run your application with spring.profiles.active meaning mvn spring-boot:run -Dspring.profiles.active=staging(Is this what you are trying to say) – Manu Aug 16 '16 at 18:41
-
Yes, using `-Dspring.profiles.active=staging` should work. You should also be able to configure this property in your Tomcat container. – g00glen00b Aug 16 '16 at 20:04