首先
pom文件引入springboot文件处理器
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional> </dependency>
resources下编写自定义配置文件
内容如下:
xdqUrl.equUrl=http://172.26.1.33:8080/xdq/substation/find_equipments
xdqUrl.equTableUrl=http://172.26.1.33:8080/xdq/sysTableInfo/find_tableId
xdqUrl.equValueUrl=http://172.26.1.33:8080/xdq/sysTableInfo/find_YCYXValue
编写自定义配置文件属性类,用来对应配置文件参数
package com.qif.xdqdm.config; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.PropertySource; import org.springframework.stereotype.Component; /** * @Title: UrlBeanProp * @ProjectName xdqdm * @Description: TODO * @date 2019/8/2 9:44 */ @Component @ConfigurationProperties(prefix = "xdqUrl") @PropertySource(value = "classpath:url.properties") public class UrlBeanProp { private String equUrl; private String equTableUrl; private String equValueUrl; public String getEquUrl() { return equUrl; } public void setEquUrl(String equUrl) { this.equUrl = equUrl; } public String getEquTableUrl() { return equTableUrl; } public void setEquTableUrl(String equTableUrl) { this.equTableUrl = equTableUrl; } public String getEquValueUrl() { return equValueUrl; } public void setEquValueUrl(String equValueUrl) { this.equValueUrl = equValueUrl; } }
综上配置完毕
项目中可以直接用
urlBeanProp.getEquValueUrl() 获取参数:
http://172.26.1.33:8080/xdq/substation/find_equipments