[会写代码的健身爱好者成长史]之@ConfigurationProperties的使用

非凡兔

关注

阅读 41

2022-01-24

@Data
@AllArgsConstructor
@NoArgsConstructor
@Component //必加 放到spring容器中
@ConfigurationProperties(prefix = "user")
public class User {

    private Integer id;
    private String userName;
    private Integer age;
    private String address;
    private String birthday;
}
<!--加这个依赖,@ConfigurationProperties注解和yml文件的配置属性进行绑定会有提示  -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
        </dependency>

 

 

精彩评论(0)

0 0 举报