注解的作用是:让使用了 @ConfigurationProperties 注解的类生效,并且将该类注入到 IOC 容器中,交由 IOC 容器进行管理
@ConfigurationProperties(prefix = "xiaomao")public class MyConfigurationProperties {// 省略 get、set、toString方法private String name;private Integer age;private String gender;}
// 注入到 IOC 容器中,交由 Spring 进行管理@Service// 该注解的作用是使 MyConfigurationProperties 这个类上标注的 @ConfigurationProperties 注解生效,并且会自动将这个类注入到 IOC 容器中@EnableConfigurationProperties(MyConfigurationProperties.class)public class HelloServiceImpl implements HelloService {}
