国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術(shù)文章
文章詳情頁

springboot如何使用@ConfigurationProperties封裝配置文件

瀏覽:84日期:2023-02-17 18:30:12
使用@ConfigurationProperties封裝配置文件

業(yè)務(wù)場景:

把配置文件的信息,讀取并自動封裝成實體類,可以使用@ConfigurationProperties,把同類的配置信息自動封裝成實體類。

1、在pom.xml中添加依賴包

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-configuration-processor</artifactId><optional>true</optional></dependency>2、創(chuàng)建配置文件(application.properties)

wx.appid = wx111111wx.redirectUri = https://www.baidu.com/wx.templateId = 1wx.first = 模板標題wx.remark = 模板備注wx.color = #000000sms.appid = 111111sms.appkey = bd3bfba026f711eaac3b005056b84de4sms.templateId = 1sms.sign = Jeff3、創(chuàng)建測試類1(WxSettings.java)

package com.jeff.config;import org.springframework.boot.context.properties.ConfigurationProperties;import org.springframework.stereotype.Component;@Component@ConfigurationProperties(prefix = 'wx')public class WxSettings {private String appid;private String redirectUri;private Integer templateId;private String first;private String remark;private String color;public String getAppid() {return appid;}public void setAppid(String appid) {this.appid = appid;}public String getRedirectUri() {return redirectUri;}public void setRedirectUri(String redirectUri) {this.redirectUri = redirectUri;}public Integer getTemplateId() {return templateId;}public void setTemplateId(Integer templateId) {this.templateId = templateId;}public String getFirst() {return first;}public void setFirst(String first) {this.first = first;}public String getRemark() {return remark;}public void setRemark(String remark) {this.remark = remark;}public String getColor() {return color;}public void setColor(String color) {this.color = color;}@Overridepublic String toString() {return 'WxSettings [appid=' + appid + ', redirectUri=' + redirectUri + ', templateId=' + templateId + ', first='+ first + ', remark=' + remark + ', color=' + color + ']';}}4、創(chuàng)建測試類2(SmsSettings.java)

package com.jeff.config;import org.springframework.boot.context.properties.ConfigurationProperties;import org.springframework.stereotype.Component;@Component@ConfigurationProperties(prefix = 'sms')public class SmsSettings {private String appid;private String appkey;private Integer templateId;private String sign;public String getAppid() {return appid;}public void setAppid(String appid) {this.appid = appid;}public String getAppkey() {return appkey;}public void setAppkey(String appkey) {this.appkey = appkey;}public Integer getTemplateId() {return templateId;}public void setTemplateId(Integer templateId) {this.templateId = templateId;}public String getSign() {return sign;}public void setSign(String sign) {this.sign = sign;}@Overridepublic String toString() {return 'SmsSettings [appid=' + appid + ', appkey=' + appkey + ', templateId=' + templateId + ', sign=' + sign+ ']';}}5、創(chuàng)建測試類(MyController.java)

package com.jeff.controller;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;import com.jeff.config.SmsSettings;import com.jeff.config.WxSettings;@RestControllerpublic class MyController {@Autowiredprivate WxSettings wx;@Autowiredprivate SmsSettings sms;@RequestMapping('myTest')public String myTest() {System.out.println(wx.toString());System.out.println(sms.toString());return 'success';}}6、打開瀏覽器訪問 http://localhost:8080/myTest,控制臺輸出結(jié)果

springboot如何使用@ConfigurationProperties封裝配置文件

springboot如何使用@ConfigurationProperties封裝配置文件

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持好吧啦網(wǎng)。

標簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 美女视频永久黄网站免费观看国产 | 欧美激情精品久久久久久久九九九 | 日韩在线精品 | 宫女淫春3在线观 | 国产精品久久久久久影院 | 亚洲最新| 性欧美高清极品xx | 奇米第四狠狠777高清秒播 | 亚洲在线免费观看视频 | 亚洲理论欧美理论在线观看 | 国产菲菲视频在线观看 | 顶级毛片在线手机免费看 | 在线看片中文字幕 | 91av视频在线| 亚洲综合久久1区2区3区 | 国产精品久久久久久久hd | 欧美一级特黄真人毛片 | 2022年国产精品久久久久 | 在线观看成年视频 | 亚洲网站免费看 | 日本加勒比网站 | 国产欧美二区三区 | 精品国产91久久久久久久a | 久久久久久久久久免观看 | 亚洲综合精品一区二区三区中文 | 欧美视频免费一区二区三区 | 国产高清精品在线 | 亚洲网址在线观看 | 国产成人亚洲综合无 | 久青草国产97香蕉在线视频xx | 成人毛片免费看 | 久久国产精彩视频 | 欧美综合视频在线观看 | 欧美高清在线精品一区 | 亚洲视频自拍 | 91亚洲欧美| 91视频久久久久 | 国内欧美一区二区三区 | 久草在线视频首页 | 亚洲国产高清一区二区三区 | 99久久www免费 |