我是靠谱客的博主 懦弱楼房,这篇文章主要介绍SpringBoot yml属性自动注入SpringBoot yml属性自动注入,现在分享给大家,希望可以做个参考。

SpringBoot yml属性自动注入

本文讲的是如何把一个yml文件中自定义的属性集合映射到一个类上


1.自定义yml 内容

// 以微信的配置为例
weixin:
  appid: xxxxxxxxx
  appSecret: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  apiSecret: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  grantType: authorization_code

2.向spring注册组件类

@Slf4j
@Data
@NoArgsConstructor
@AllArgsConstructor
@Component
@ConfigurationProperties(prefix = "weixin")
public class WeixinProperti

最后

以上就是懦弱楼房最近收集整理的关于SpringBoot yml属性自动注入SpringBoot yml属性自动注入的全部内容,更多相关SpringBoot内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(95)

评论列表共有 0 条评论

立即
投稿
返回
顶部