关与 @EnableConfigurationProperties 注解

@EnableConfigurationProperties注解的作用是:
  让使用 @ConfigurationProperties 注解的类生效。
  当@EnableConfigurationProperties注解应用到你的@Configuration时, 任何被@ConfigurationProperties注解的beans将自动被Environment属性配置。 这种风格的配置特别适合与SpringApplication的外部YAML配置进行配合使用。

application.yml配置文件

userbody: name: 测试 password:
123456 birthday: 1992.10.28 mobile: 138027897343 address: 北京市西城区
实体类:

@ConfigurationProperties(prefix = "user") @Data @NoArgsConstructor @AllArgsConstructor public class User { private Long id; private String age; private String name; private String password; private String birthday; private String mobile; private String address; }

Controller层上:

@EnableConfigurationProperties({User.class})
对应实体类User
原文地址:https://www.cnblogs.com/crazy-lc/p/11801050.html