Use preamble:
1. In the spring development process, we often use the @ConfigurationProperties annotation, which is usually used to convert properties and yml configuration file properties into bean objects for use.
application.yml:
Custom classes corresponding to configuration files:
The above steps can register configuration file properties into the IOC container. Before obtaining these beans, you first need to use the @EnableConfigurationProperties({ConfigBean.class}) annotation to make the ConfigurationProperties annotation take effect:
At this point, you can get the custom annotation bean object
Test results:
2. In addition to the above methods, you can also add the @Component annotation to the @ConfigurationProperties annotated class or inject the @ConfigurationProperties annotated class into the spring container.
Note: The @Component annotation indicates that a class will be used as a component class, and then spring will create beans for the class.
The @Bean annotation tells Spring that the method will return an object that is registered as a bean in the Spring application context.