Use of springboot configuration files

Table of contents

1.application.properties is the default configuration file of springboot, but it is cumbersome, and generally uses .yml files

2. The role of the configuration file

3. Use of configuration files


1.application.properties is the default configuration file of springboot, but it is cumbersome, and generally uses .yml files

        ①、properties

        ②、.yml

2. The role of the configuration file

        Assign values ​​to the related classes of the configuration, and load them automatically when the class starts

3. Use of configuration files

        ①、@value("${aaa.bbb}")

        ②. Configuration files have priority: configuration files in the external config folder > external configuration files > built-in configuration files (the priority of the .properties file in the built-in configuration file is higher than that of the .xml file (for convenience, We generally delete the .properties file directly););

        ③. Priority verification (package to the server)

                a. Set the server and port number in the configuration file

                     

                b. clean is to delete the target file, and package is to add the target file

                c. Move the jar package to the server, open the location where the jar package is located, and start the jar package java-jar

                d. Put the configuration file in src/main/resources/ into the server (the built-in configuration file is called when packaging, and the external configuration file found in the file package here)

                e. The external configuration file takes precedence over the built-in configuration file, and will follow the external configuration file

                f. Create a config folder, put the configuration file in it, and it will follow the configuration in the config file

        ④, application

        The configuration file of the production environment cannot be localized, it only needs to be modified in the external configuration file

        ⑤. Add this annotation in the configuration class, the prefix of the configuration file is

                

        ⑥, pay attention

        If the class is not handed over to spring for management, @value cannot get the value, and it needs to be taken from spring when it is used, and it cannot be new by itself

Guess you like

Origin blog.csdn.net/qq_52240237/article/details/132127863