I can see many posts regarding environment specific properties, but none of them is quite solving my problem.
I'm working on my spring boot app, which will have say two profiles dev/live.
I want my project to have the following structure:
--deployment
--dev
--myapp.properties
--live
--myapp.properties
--src
--main
--java
--resources
--test
--java
I know that if I had two application.properties
in my resources folder, say application-live.properties
and application-dev.properties
I'd be able to tell maven which one to pick at application start time using:
Dspring.profiles.active=profile_name
But I don't like name of this generic properties file. So I found this way to tell the application where to look for profile specific properties in /deployment/<profile>/
.
I did it using Maven build task configuration:
<build>
<resources>
<resource>
<directory>deployment/${environment}</directory>
<includes>
<include>*.properties</include>
<include>*.xml</include>
</includes>
</resource>
</resources>
</build>
This is going to search for resources in deployment/<profile>
and include them. Good thing is that Maven finds the correct environmental property files, but unfortunately it includes them in target/classes/myapp.properties
which seems invisible for Spring Boot? How can I tell Maven to place it in the same directory as application.properties
or alternately how can I tell Spring Boot to find it where it is at the moment?
Thanks a lot!
How can I tell Maven to place it in the same directory as application.propertiesor alternately how can I tell Spring Boot to find it where it is at the moment?
1) you don't need to modify Maven settings because it places config file to the right place: target/classes
is the root of the classpath, because all files from this directory will copied into the WEB-INF/classes
directory of you WAR/JAR file.
2) to change name of the properties file from you can use spring.config.name
property by explicitly passing it as -Dspring.config.name=myapp
or as environment variable SPRING_CONFIG_NAME=myapp
. More information you can find in the Change the location of external properties of an application chapter of the official documentation.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.