- @ConfigurationProperties是springboot提供读取配置文件的一个注解
- @component是spring中的一个注解,它的作用是实现bean的注入
示例:
@Data
@Component
@ConfigurationProperties(prefix = "mycar")
public class Car {
private String brand;
private Integer price;
}
application.properties文件
server.port=8080 mycar.brand=BYD mycar.price=100000 debug=true
这里运行出来,就可以在页面上获取到 car的 值了
- @EnableConfigurationProperties注解的作用是:使 某个使用 @ConfigurationProperties 注解的类生效
- @ConfigurationProperties是springboot提供读取配置文件的一个注解
示例:
@Data
//@Component
@ConfigurationProperties(prefix = "mycar")
public class Car {
private String brand;
private Integer price;
}



