1.配置文件所有固定前缀的 都可以使用SpringBoot自动注入实体类如下配置
配置文件:application.properties
固定前缀: sys.test.config
配置信息:
sys.test.config.industryKey=aaa
sys.test.config.systemName=bbb
sys.test.config.downloadUrl=ccc
sys.test.config.traceDomain=ddd
2.SpringBoot实体类
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Component
@ConfigurationProperties(prefix = "sys.test.config")
public final class ResourceContainer {
private String industryKey;
private String systemName;
private String downloadUrl;
private String traceDomain;
public String getIndustryKey() {
return industryKey;
}
public void setIndustryKey(String industryKey) {
this.industryKey = industryKey;
}
public String getSystemName() {
return systemName;
}
public void setSystemName(String systemName) {
this.systemName = systemName;
}
public String getDownloadUrl() {
return downloadUrl;
}
public void setDownloadUrl(String downloadUrl) {
this.downloadUrl = downloadUrl;
}
public String getTraceDomain() {
return traceDomain;
}
public void setTraceDomain(String traceDomain) {
this.traceDomain = traceDomain;
}
}
3.使用方式
@Autowired
private ResourceContainer resourceContainer;