@ConfigurationProperties vs. @Value

@Value 是一个核心容器特性,它不提供与类型安全配置属性相同的特性。下表总结了 @ConfigurationProperties@Value 支持的特性:

特性@ConfigurationProperties@Value
Relaxed bindingYESNO
Meta-data supportYESNO
SpEL evaluationNoYes

If you define a set of configuration keys for your own components, we recommend you to group them in a POJO annotated with @ConfigurationProperties. Please also be aware that since @Value does not support relaxed binding, it isn’t a great candidate if you need to provide the value using environment variables.

如果您为自己的组件定义了一组配置键,我们建议您将它们分组到一个带有 @ConfigurationProperties 注释的 POJO 中。还请注意,由于 @Value 不支持 relaxed binding,如果您需要使用环境变量提供相应的值,那么它不是一个很好的选择。

Finally, while you can write a SpEL expression in @Value, such expressions are not processed from Application property files.

最后,虽然可以在 @Value中编写 SpEL 表达式,但是这些表达式并不从应用程序属性文件中处理。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值