Springboot start reading external configuration file __springboot

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.