In springboot, there are the following problems when binding the properties in the class with the configuration in the configuration file:
When using @ configurationproperties, the following prompt appears at the top of idea:
Click the prompt to jump to the official document, and then add the following configuration in POM. XML
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional> </dependency>
The effect after adding is that when you write the configuration file (YML, properties configuration file), you will be prompted
After the above is finished, @ configurationproperties will report an error below. You can see it according to the prompt
Not registered via @ enableconfigurationproperties or marked as spring component @ Enable configuration properties (person. Class),
After adding, the error is really gone, but in the unit test of springboot, you will see the following error: could not autowire. No beans of ‘person’ type found
Go back to the user-defined bean person, add the annotation @ component and declare to add the component to the container so that it can be used?
“Only if this component is a component in the container can the @ configurationproperties function provided by the container be used.”