What I want to solve is as the title says. In spring-boot, DB connection information etc. are often written in application.properties under src / main / resources, but I will explain how to put this file externally and operate it with a definition different from that at compile time. I will. Previously, I posted "How to use Maven to place resource files outside JAR", but it is the spring-boot version of it. ..
It's really easy with spring-boot. Simply place the resource file (application.properties, etc.) you want to place externally in another folder and specify it as the classpath at runtime.
That is, if you run my-java-app.jar and want to load application.properties in the external_resource folder, include the external_resource folder in your runtime classpath.
Folder structure
my-java-app.jar
external_resource
└ application.properties
command
java -classpath ./external_resource -jar my-java-app.jar
The reason for this behavior is that in spring-boot, the resource file read priority is as follows.
In fact, there is a more detailed definition of read priorities, as others have explained below.
I'm grateful that spring-boot can reach the itchy place nicely. And thank you to @niwasawa for translating the official documentation.
Recommended Posts