Different application.properties files for development and production in jmix

In jmix app, in application.properties config file I have this 2 blocks

1 for test and dev purposes

main.datasource.jdbcUrl = jdbc:postgresql://srv/mydatabase
main.datasource.username = postgres
main.datasource.password =123

2 and this for production

#main.datasource.jdbcUrl = jdbc:postgresql://localhost/mydatabase
#main.datasource.username = postgres
#main.datasource.password =mypass

When I make war file I decomment block 2 and comment block 1 to have the proper connection params.

Is there a solution to have 2 application.properties files and tell the graddle when making war file to choose the one for production ? Or how i should do it right ?


Spring Boot has a Profiles feature for your exact needs.

See example how it is used in the Jmix deployment recipe:

It is not straight the documentation.

Here is my situatiuon, may be y can help me.
In Intelij, i have 3 application.properties resource files.
1.) application.properties with all settings except database connection. Also I have put
2.) application-dev.properties with connection for development
3.) application-prod.properties with connection for production

In Intelij, Run configuration for jmix app I have added environment variable: spring.profiles.active=dev.
When building jmix app from Intelij and run it is ok, it takes the right connection from -dev properties file.

But when i build gradle war file it doesn’t work. I have added also environment variable spring.profiles.active=prod for war gradle run configuration.
How can I tell gradle to take that =prod file when building the war file ?

In build.gradle i have added:
apply plugin: ‘war’
war {
and added the environment variable for run configuratuin for war

The environment variable should be specified at the run time, on the target server where the WAR file is deployed to the Tomcat.
One WAR file can be used for several deployments with different profiles (dev, prod, aws, …).

I put spring.profiles.active=prod on the prod server (windows environment variables if os is windows) and worked.