其他分享
首页 > 其他分享> > ConfigurationProperties和Value

ConfigurationProperties和Value

作者:互联网

ConfigurationProperties和Value
https://blog.csdn.net/qq_45678953/article/details/117266855

SpringBoot之ConfigurationProperties和Value注解的区别

1.@ConfigurationProperties和@Value获取值的比较
@ConfigurationProperties@Value
功能批量注入配置文件中的属性一个个指定
松散绑定(松散语法)支持不支持
SpEL不支持支持
JSR303支持不支持
复杂类型封装支持不支持

无论使用@ConfigurationProperties还是@Value都可以获取到值

如果说, 我们只是在某个业务逻辑中需要获取一下配置文件中某项的值, 使用@Value

如果说, 我们专门编写了一个JavaBean来和配置文件进行映射, 我们就直接使用@ConfigurationProperties

解释

标签:name,配置文件,JSR303,Value,person,ConfigurationProperties
来源: https://www.cnblogs.com/sunny3158/p/16553910.html