方法一
package com.tongtech.space.common.configs;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* @author
* @Date: 2020/8/19 16:04
*/
@Component
@ConfigurationProperties(prefix = "ask")
public class BeiJingAskConfig {
/**
* 获取我的办件本信息地址
*/
private String url;
/**
* #获取办件基本信息接口地址
*/
private String infoUrl;
/**
* 办件token
*/
private String token;
/**
* 办件areacode
*/
private String areacode;
//省略get set 方法
}
//使用的时候
@Resource
private BeiJingAskConfig config;
方法二
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
@Component
public class PropertyUtil {
@Autowired
private Environment env;
private static Environment props;
@PostConstruct
public synchronized void init() {
props = env;
}
public static String getProperty(String key){
return props.getProperty(key);
}
public static String getProperty(String key, String defaultValue) {
return props.getProperty(key, defaultValue);
}
}
//使用的时候
String testaa = PropertyUtil.getProperty("back.url.recommendurl");