The starting dependencies of springboot

Way 2 to load auto configuration:

 

 The way springboot reads the configuration file:

1. Read the core configuration file

The core configuration file refers to the application.properties or application.yml configuration file in the resources root directory. There are two ways to read these two configuration files, both of which are relatively simple.

Method 1: Use the @Value method (commonly used); the ${} of @Value contains the key name in the core configuration file

Method 2: Use the Environment method; this method is done by dependency injection Evnironment. Add @Autowired annotation to the created member variable private Environment env to complete dependency injection, and then use env.getProperty("key name") to complete Read the corresponding value.

2. Read the custom configuration file

In order not to destroy the original ecology of the core files, but need to have custom configuration information, in general, a custom configuration file will be selected to put these custom information, and here the resourcesconfiguration file author.properties is created in the directory.

Note:
    There are two properties in the @ConfigurationProperties annotation:
locations: specify the location of the configuration file
prefix: specify the prefix of the key name in the configuration file (all key names in my configuration file start with author.)
    Using @Component is Make the class available to be used by dependencies elsewhere, i.e. use the @Autowired annotation to create instances.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324885617&siteId=291194637