How Spring boot reads the properties file outside the jar package

Source: Internet
Author: User

Let's start with the file structure of target directory.

The properties file is stored in the Conf folder,

The Lib folder contains a variety of jar files,

Start.bat is the startup file for the Windows command line.

What to do in the properties file

1. Create a configuration file-related configuration class with each properties file corresponding to a configuration class

The @configurationproperties is used here,

Prefix refers to a prefix in the properties file, such as Asdf.name, where the prefix is asdf, and the name in the entity class corresponds to the name behind ASDF.

Locations is the address of the properties file, here I use file, not classpath, use classpath always problem, do not know why. The Conf folder is because the start command line is at the target root directory, and the directory that is currently running is the target root directory.

2. Add @enableconfigurationproperties in the application class

There are several configuration classes that you will add.

3. Import in the place you want to use

4. You can use the

How Spring boot reads the properties file outside the jar package

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.