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内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复