We know that @Value provides flexibility in injecting the Value of a key-value pair from a configuration file into a Bean, but this is not enough, as shown below in application.properties
Mysql. Url = "http://127.0.0.1:3306/wiki" mysql. The userName = admin mysql. Password = adminCopy the code
To reduce duplication, Spring Boot provides us with the @ConfigurationProperties annotation. Properties can be loaded into the bean at once.
Note:
1. @ ConfigurationProperties cooperate with @ Component or @ EnableConfigurationProperties a use, to take effect.
2.@ConfigurationProperties also supports reading configuration information from yML files.
However, the following conditions must be met:
-
Yml or bootstrap.yml; otherwise, the configuration data cannot be read
-
Annotations map reading class 】 【 remember to add @ Component or @ EnableConfigurationProperties (XXX. Class), where XXX. Class using annotations @ ConfigurationProperties (” XXX, XXX “)