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;
   }
 }
posted @ 2018-03-21 17:55  qwer78  阅读(69)  评论(0)    收藏  举报