午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

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

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

瀏覽:234日期: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)文章:
主站蜘蛛池模板: 欧美日韩亚洲综合 | www.欧美视频| 亚洲一区 在线播放 | 高跟鞋肉丝交足91 | 奇米影视久久 | 亚洲国产精品久久久久久6q | 久久精品视频18 | 亚洲第一视频在线 | 欧美一级特黄视频 | 青青青视频在线免费观看 | 中文字幕精品一区二 | 五月激情综合网 | 牛人盗摄一区二区三区视频 | 激情久久五月天 | 婷婷av在线 | 黄色在线网 | 日韩视频a | 日韩一区二区三区四区 | 女人的天堂网站 | 日韩美女免费视频 | 国产免费黄色片 | 国产真人真事毛片视频 | 久草视频在线看 | www黄色com | 亚洲精品视 | 玉足女爽爽91 | 黄色永久视频 | av最新网址| 久久三 | 日韩一区二区免费在线观看 | 国产精品网页 | 黄色在线观看国产 | 欧美精品免费一区二区三区 | 亚洲免费在线播放 | 亚洲午夜18毛片在线看 | 四虎www.| 中文字幕一区二区三区四区欧美 | 成人影片在线免费观看 | 夜夜操夜夜爽 | 人人看人人看 | 黄网在线视频 |