1.@ConfigurationProperties和@Value的区别
- 将配置文件中配置的每一个属性的值,映射到这个组件中
- @ConfigurationProperties:告诉Springboot将本类中的所有属性和配置中的相关属性进行绑定(默认从全局配置文件2中获取值)
- prefix = “person”:配置文件中哪个下面的所有属性进行–映射
- 只有这个组件是容器中的组件,才能用容器提供的@ConfigurationProperties(prefix = “person”)
- @ConfigurationProperties:能一次性配置多个属性,@Value只能一次一个
- @ConfigurationProperties:能支持lastNamehe1last-name转换,@Value不能
- @ConfigurationProperties:不支持表达式例如2*3,@Value支持
- @ConfigurationProperties:支持校验,@Value不支持
- @ConfigurationProperties:支持复杂类型封装,@Value不支持
2.PropertySource的用法
//加载指定配置文件
//@PropertySource(value = "classpath:person.properties")
- 可以使用指定的配置文件
@ConfigrationProperties默认使用application.properties配置文件