概述
SpringBoot项目加载yml配置文件中的数据,可以把配置文件的信息,读取并自动封装成实体类,这样子,我们在代码里面使用就轻松方便多了,这时候,我们就可以使用@ConfigurationProperties,它可以把同类的配置信息自动封装成实体类。
列如,需要加载如下配置文件的中参数:
定义一个实体类与上面参数一一对应就可以了,如下:
@Component
@ConfigurationProperties(prefix="connection")
public class ConnectionSettings {
private String platform;
private String pageSize;
private String platSysId ;
private String uploadSaveDir ;
private String uploadVisitBaseUrl ;
private String restHosUrl ;
private String restBdpUrl ;
private String restNhsUrl ;
private String restPayUrl ;
private String manHosUrl ;
private String manBdpUrl ;
private String manNhsUrl ;
public String getPlatform() {
return platform;
}
public void setPlatform(String platform) {
this.platform = platform;
}
public String getPageSize() {
return pageSize;
}
public void setPageSize(String pageSize) {
this.pageSize = pageSize;
}
public String getPlatSysId() {
return platSysId;
}
public void setPlatSysId(String platSysId) {
this.platSysId = platSysId;
}
public String getUploadSaveDir() {
return uploadSaveDir;
}
public void setUploadSaveDir(String uploadSaveDir) {
this.uploadSaveDir = uploadSaveDir;
}
public String getUploadVisitBaseUrl() {
return uploadVisitBaseUrl;
}
public void setUploadVisitBaseUrl(String uploadVisitBaseUrl) {
this.uploadVisitBaseUrl = uploadVisitBaseUrl;
}
public String getRestHosUrl() {
return restHosUrl;
}
public void setRestHosUrl(String restHosUrl) {
this.restHosUrl = restHosUrl;
}
public String getRestBdpUrl() {
return restBdpUrl;
}
public void setRestBdpUrl(String restBdpUrl) {
this.restBdpUrl = restBdpUrl;
}
public String getRestNhsUrl() {
return restNhsUrl;
}
public void setRestNhsUrl(String restNhsUrl) {
this.restNhsUrl = restNhsUrl;
}
public String getRestPayUrl() {
return restPayUrl;
}
public void setRestPayUrl(String restPayUrl) {
this.restPayUrl = restPayUrl;
}
public String getManHosUrl() {
return manHosUrl;
}
public void setManHosUrl(String manHosUrl) {
this.manHosUrl = manHosUrl;
}
public String getManBdpUrl() {
return manBdpUrl;
}
public void setManBdpUrl(String manBdpUrl) {
this.manBdpUrl = manBdpUrl;
}
public String getManNhsUrl() {
return manNhsUrl;
}
public void setManNhsUrl(String manNhsUrl) {
this.manNhsUrl = manNhsUrl;
}
}
最后
以上就是明理西装为你收集整理的SpringBoot注解之@ConfigurationProperties的全部内容,希望文章能够帮你解决SpringBoot注解之@ConfigurationProperties所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复