Is it possible to have multiple application.properties files? ( EDIT : note that this question has evolved with the one on the title.)
I tried to have 2 files.
- The first is in the root folder in the Jar application.
- The second is in the directory specified in the class path.
2 files are called "application.properties".
Is it possible to "merge" the contents of both files? (and the second value of the property overrides the first) Or, if I have one file, then the other file is ignored?
UPDATE 1 : content can be merged. Yesterday it seemed that the first was ignored, but it seems that this is because then something was broken. Now it works well.
UPDATE 2 : he is back! Again, only one of the two files applies. This is weird ... It started after I created the jar application file using the Spring Tool Suite. And it seems that the Jar version always ignores the second (in the classpath), while the behavior of the extended version that runs on STS changes. Where can I start the investigation?
UPDATE 3 :
The behavior of the Jar version was actually correct. This is the specification of java.exe. When the -jar parameter is specified, java.exe ignores the -classpath parameter and the CLASSPATH environment variable, and the class path will contain only the jar file. Thus, the second application.properties file in the classpath is ignored.
Now, how can I load the second application.properties file in the classpath?
UPDATE 4 :
I was able to load the application.properties file in the external path when using the -jar option.
The key was PropertiesLauncher.
To use PropertiesLauncher, the pom.xml file must be modified as follows:
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <layout>ZIP</layout> </configuration> </plugin> </plugins> </build>
For this, I referred to the following StackOverflow question: spring failed to use the property loading utility . BTW, In Spring Boot Maven boot file ( http://docs.spring.io/spring-boot/docs/1.1.7.RELEASE/maven-plugin/repackage-mojo.html ), there is no mention of triggers being set ZIP used by PropertiesLauncher. (Maybe in another document?)
After the jar file was created, I could see that the PropertiesLauncher property was used by checking the Main-Class property in META-INF / MENIFEST.MF in the bank.
Now I can start the jar as follows (on Windows):
java -Dloader.path=file:///C:/My/External/Dir,MyApp-0.0.1-SNAPSHOT.jar -jar MyApp-0.0.1-SNAPSHOT.jar
Note that the application jar file is included in loader.path.
The application.properties file is now loaded in the C: \ My \ External \ Dir \ config folder.
As a bonus, any file (for example, a static html file) in this directory can also be accessed by the bank, since it is in the bootloader path.
As for the non-jar (extended) version mentioned in UPDATE 2, there may have been a problem with the order of the classpath.
(By the way, I changed the title of the question to be more specific for this problem.)