Spring注解无法注入静态变量

参考:https://blog.csdn.net/BuquTianya/article/details/49009831

1.使用xml方式声明Bean,在xml中注入静态变量; 

  
2.使用一个非静态的变量注入,然后在@PostConstruct标记的方法中给静态变量赋值。

3,在静态方法中获取bean

AppConfMapper appConfMapper = (AppConfMapper) BeanHoldFactory.getApplicationContext().getBean("appConfMapper");

 4,给静态变量设置Setter方法,在Setter方法上加注入操作就可以了

posted @ 2018-07-23 16:10  wanhua.wu  阅读(793)  评论(0编辑  收藏  举报