search
HomeJavajavaTutorialHow does springboot find the order and priority of configuration file paths?

    The order in which configuration file paths are searched and their priorities

    1. The order in which springboot searches for configuration file paths and their priorities

    In the project class, there are four places that the system will automatically scan:

    1.file:/config/

    2.file:/

    3.classPath:/config/

    4.classPath:/

    1) Its file validity priority level is from top to bottom, that is, if there are the same attributes in different paths, the path attributes above will be selected first (1>2> ;3>4)

    2) The path scanning order is opposite to its priority (4>3>2>1). The later ones will overwrite the previous ones, and all paths will be scanned, forming a complement.

    2. Under the same path

    application.properties(application.yml), bootstrap.properties(bootstrap.yml) loading order and priority

    1. Comparison between application and bootstrap (prefix comparison)

    Tip: Bootstrap type files will only take effect when springcloud related configuration is introduced in multi-service projects. Springboot will not automatically scan The bootstrap file will only scan the application file, so the comparison between the two is only meaningful in the spingcloud multi-service project.

    1) Loading order: If application and bootstrap are in the same directory: bootstrap loads application first and then loads

    Bootstrap properties have higher priority. By default, they will not Overridden by local configuration. (This is what the Internet and the official say, but after my own testing, I found that application will override bootstrap. My understanding is that all bootstrap attributes have priority over application. Only the configuration related to the underlying system will be higher. There are different opinions. Brother, welcome to discuss)

    3) Difference: Both bootstrap and application can be used to configure parameters.

    Bootstrap is used for early application boot and configuration information reading. It can be understood as some parameter configurations at the system level. These parameters generally do not change. Once bootstrap is loaded, the content will not be overwritten.

    application.yml can be used to define application-level, application-specific configuration information, and can be used to configure public parameters to be used in subsequent modules, etc.

    4) Typical application scenarios of bootstrap (classic three points)

    • 1. When using the Spring Cloud Config Server configuration center, you need to specify it in bootstrap.yml In the spring.applicatio configuration file n.name and spring.cloud.config.server.git.uri, add the configuration properties connected to the configuration center to load the configuration information of the external configuration center

    • 2. Some fixed properties that cannot be overwritten

    • 3. Some encryption/decryption scenarios

    2. .properties and .yml comparison (suffix comparison)

    1) Loading order

    .yml precedes .properties

    2)Priority level

    .properties Prior to .yml, because .properties will overwrite .yml when loaded later

    3) Difference

    • 1.yml has a natural tree structure, and properties are key-value pairs ;

    • 2. The properties file is separated by ".", and the .yml is separated by ":";

    • 3. You must not use TAB for indentation in .yml, otherwise a very strange error will be reported;;

    • 4.yml is more friendly to Chinese support than .properties.

    • 5.yml is cross-language: it can be used in a large number of languages ​​including JAVA, go, python, etc. For example, when using go and java for cloud computing, you can use the configuration center Use the same configuration!

    • 6. When customizing the configuration file, you can only use properties, because spring only has the @PropertiesSource annotation that can introduce custom annotations and has no support for yml

    Summary: In the same level directory, the priority level application>bootstrap,.properties>,yml, the prefix is ​​greater than the suffix, and the file path is greater than the file name

    The reason why the springboot configuration file does not take effect

    1. Change the packaging method to jar.

    <packaging>jar</packaging>

    2. It may be that the shortened format of the yml file is incorrect, just check it carefully.

    3. Also, yours is not a boot project at all, application.yml does not have a leaf mark

    1. Click on the project structure

    How does springboot find the order and priority of configuration file paths?

    ##2. Open the module and click once

    How does springboot find the order and priority of configuration file paths?

    3.

    How does springboot find the order and priority of configuration file paths?##4.Refactor the project

    The above is the detailed content of How does springboot find the order and priority of configuration file paths?. For more information, please follow other related articles on the PHP Chinese website!

    Statement
    This article is reproduced at:亿速云. If there is any infringement, please contact admin@php.cn delete
    Java compilation error: How do package declaration and access permissions change after moving the class file?Java compilation error: How do package declaration and access permissions change after moving the class file?Apr 19, 2025 pm 07:12 PM

    Packages and Directories in Java: The logic behind compiler errors In Java development, you often encounter problems with packages and directories. This article will explore Java in depth...

    Is JWT suitable for dynamic permission change scenarios?Is JWT suitable for dynamic permission change scenarios?Apr 19, 2025 pm 07:06 PM

    JWT and Session Choice: Tradeoffs under Dynamic Permission Changes Many Beginners on JWT and Session...

    How to properly configure apple-app-site-association file in pagoda nginx to avoid 404 errors?How to properly configure apple-app-site-association file in pagoda nginx to avoid 404 errors?Apr 19, 2025 pm 07:03 PM

    How to correctly configure apple-app-site-association file in Baota nginx? Recently, the company's iOS department sent an apple-app-site-association file and...

    What are the differences in the classification and implementation methods of the two consistency consensus algorithms?What are the differences in the classification and implementation methods of the two consistency consensus algorithms?Apr 19, 2025 pm 07:00 PM

    How to understand the classification and implementation methods of two consistency consensus algorithms? At the protocol level, there has been no new members in the selection of consistency algorithms for many years. ...

    What is the difference between IS TRUE and =True query conditions in MySQL?What is the difference between IS TRUE and =True query conditions in MySQL?Apr 19, 2025 pm 06:54 PM

    The difference between ISTRUE and =True query conditions in MySQL In MySQL database, when processing Boolean values ​​(Booleans), ISTRUE and =TRUE...

    How to avoid data overwriting and style loss of merged cells when using EasyExcel for template filling?How to avoid data overwriting and style loss of merged cells when using EasyExcel for template filling?Apr 19, 2025 pm 06:51 PM

    How to avoid data overwriting and style loss of merged cells when using EasyExcel for template filling? Using EasyExcel for Excel...

    See all articles

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    AI Hentai Generator

    AI Hentai Generator

    Generate AI Hentai for free.

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    Dreamweaver Mac version

    Dreamweaver Mac version

    Visual web development tools

    WebStorm Mac version

    WebStorm Mac version

    Useful JavaScript development tools

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment