springboot start reading external configuration file
Sometimes the project is packaged into a jar or war, running the Springboot project with the Java-jar command, because the Springboot project has its own application.properties profile, but after we finish the package, it will also hit the inside of the package. But also can open the compression package modify properties file, but also more trouble.
Now have the following requirements, such as customers need to deploy a set of projects in many servers, but their database connection is not the same, we can not pin for so many servers, packaging, very disgusting, of course, you can play the package, copy a bunch, respectively modify the package inside the configuration file. Springboot has the option of reading external configuration files, such as Next priority: the first is to build a config folder in the same directory as the jar package, and then put the configuration file under this folder. The second is to put the configuration file directly into the same sibling directory as the jar package. The third is to build a config folder under Classpath, and then put the configuration file in. The fourth type is to put the configuration file directly under Classpath.
See above priority. That is, springboot default is to read a config/application.properties file in its own sibling directory. The application.properties files that we usually create under the Src/main/resources folder are actually the lowest priority ....
Below this is the Config/application.properties file placement location. In advance I set its port to 1000, and the war package also has a application.properties file, and its port is 3000.
direct command execution:
Java-jar Cloud-lyzx-project.war
It is true that the access port is 1000, not the 3000 inside.
And then I got outside, and this is the Application.properties file placement location. In advance I set its port to 2000
Start the jar package directly at the current location:
Java-jar Cloud-lyzx-project.war
You will find that the access port is 2000, not 3000 inside.