@value()给static变量赋初始值始终为null

 
@Component   //别丢了
public class UrlUtil {
  @Value("${conf.corp.id}")
  private static String CORPID;
}

  

这样始终是null。

  可用set方法为其赋值


@Component
public class UrlUtil {
  private static String CORPID;    // = "wx3a42b774b7b91ccf";

  @Value("${conf.corp.id}")
  public void setCORPID(String id) {
      CORPID = id;
  }
}

 

posted on 2017-03-06 17:28  凶狠恶霸罗  阅读(371)  评论(0编辑  收藏  举报

导航