在类上面打上
@ConfigurationProperties(prefix="xxx.xxx") 然后springboot就能自动找到在application.properties或yml文件中定义好要注入的属性的值。但是在类中要为要注入值的属性提供set/get方法。 如@ConfigurationProperties(prefix="myself”),则会在配置文件中找前缀为myself的所有配置: myself.name=xxx myself.age =18 找到后将值注入到属性进去。 |
那么@ConfigurationProperties和 spring底层注解@Value有什么区别呢?
1.@ConfigurationProperties可以批量注入;@Value只能一个一个的指定注入
2.@Value注解支持EL语法;@ConfigurationProperties不支持。