spring-boot之@ConfigurationProperties的使用

个人博客导航页(点击右侧链接即可打开个人博客):大牛带你入门技术栈 

@ConfigurationProperties是什么?

Using the @Value("${property}") annotation to inject configuration properties can sometimes be cumbersome, especially if you are working with multiple properties or your data is hierarchical in nature. Spring Boot provides an alternative method of working with properties that lets strongly typed beans govern and validate the configuration of your application.

上面就是官方文档的解释,如果你想使用多个属性或者你的数据是由层次结构的,那么就可以使用@ConfigurationProperties来处理

那么什么是层次的结构呢,实际上就是我们开发过程中说的属性的嵌套,例如一个Person 类中有一个引用类型是Address 那么这种就是有层次结构的


那么怎么使用呢

Spring Boot provides infrastructure to bind @ConfigurationProperties types and register them as beans. You can either enable configuration properties on a class-by-class basis or enable configuration property scanning that works in a similar manner to component scanning.

大概意思是说spring-boot对绑定@ConfigurationProperties 提供了一个基础的功能,你可以通过扫描组件或者通过创建类的方式进行,那么常用的大概有这几种

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值