YML, properties configuration file
Yml compared to the properties configuration file, Yml can omit unnecessary prefixes and look more layered. It is recommended to use the Yml file.
@Value
To obtain the corresponding value from the configuration item for the profile, the value @Value must be the same as the configuration entry in the configuration file, using the following method:
@ConfigurationProperties
When there are too many configuration items, it is more convenient to use @configurationproperties annotations. And you can group different configuration items. Example: Configuration items are divided into project and Johnson two different configuration items
The prefix that corresponds to the value of the @ConfigurationProperties. The property name must correspond to the configuration item. and implement the corresponding get, set method.
Here's how to use it:
@Component
Because in the persistence layer, the business layer and the control layer, respectively uses the @repository, the @Service and the @controller, because does not know this class belongs to which stratification plane, but also to spring management, therefore uses the @component.
Look at the project class and the Johnson class to see.
Multi-environment configuration
In most development, general configuration items separate the production and test environments. If you are using the same profile, it can be cumbersome to constantly modify the configuration between production and test environments, and development efficiency will be very low.
and spring.profiles.active just can solve this problem.
Note: Naming requires specification, you must use the symbol "-" to differentiate files.
Wood is just a small white, if there is not good or better suggestions, please leave a message or send to my QQ mailbox [email protected]. Thank you all ~ (*^▽^*)
Spring Boot's Getting started configuration (i)