yml, properties configuration file
Compared with the properties configuration file, yml can omit unnecessary prefixes and look more hierarchical. yml files are recommended.
@Value
Obtain the corresponding value according to the configuration item in the configuration file. The value of @Value must be consistent with the configuration item in the configuration file. The usage method is as follows:
@ConfigurationProperties
When there are too many configuration items, it is more convenient to use the @ConfigurationProperties annotation. And different configuration items can be grouped. For example: configuration items are divided into two different configuration items: project and Johnson
The prefix corresponding to the value in @ConfigurationProperties. The property name must correspond to the configuration item. And implement the corresponding get and set methods.
The method of use is as follows:
@Component
Because in the persistence layer, business layer and control layer, @Repository, @Service and @Controller are used respectively, because it is not clear which level this class belongs to, and it has to be managed by Spring, so @Component is used.
You can see the project class and Johnson class in the above figure.
Multi-environment configuration
In most development, common configuration items will separate the production environment from the test environment. If the same configuration file is used, it will be very troublesome to constantly modify configuration items between the production and test environments, and the development efficiency will be very low.
And spring.profiles.active can just solve this problem
Note: The naming needs to be standardized, and the symbol "-" must be used to distinguish files.
Mumu is just a novice. If the writing there is not good or if you have better suggestions, please leave a message or send it to my QQ mailbox [email protected]. Thank you everyone~(*^▽^*)