springboot @value注入static对象 与 application.properties 与 pom.xml 取值
1.在pom.xml文件里的properties定义一个参数
2.定义完了,在application.properties中获取这个值
server.port=8090
#@pom.xml中的一个参数名@
war.name= @war.name@
api.path= https://www.baidu.com/${war.name}/
3.在constant中引用
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
/**
* 全局常量
*/
@Component
public class Constants{
public static String API_URL;
@Value("${api.path}")
public void setApiUrl(String apiUrl) {
this.API_URL = apiUrl;
}
}

浙公网安备 33010602011771号