标签:blog fresh ack param 参考 静态 new value class
第一步:写注解@Component 使当前类成为一个bean对象。(@Controller,@service都行)
第二步:写个static的变量
第三步:写个@PostConstruct注解注解注释的方法,在这个方法里,将自动注入的值赋值给定义的static变量
第四步:static变量替代自动注入在static方法里面使用
@Component public class DSHWechatApiUtil extends DSHBaseController { @Autowired private static IThirdPartyAuthDao staticThirdPartyAuthDao; @PostConstruct public void init() { staticThirdPartyAuthDao = thirdPartyAuthDao; } public static JSONObject getAuthorizerToken(String componentAccessToken, String authorizerAppid, String authorizerRefreshToken) { JSONObject returnObject = new JSONObject(); try { if (DSHUtils.isEmpty(componentAccessToken)) { componentAccessToken = staticThirdPartyAuthDao.selectWechatValue(DSHConstants.WECHAT_PARAMS.COMPONENT_ACCESS_TOKEN); } } catch (Exception e) { e.printStackTrace(); } return returnObject; } }
注意:
参考文章:
https://blog.csdn.net/qq_23167527/article/details/77994677
https://blog.csdn.net/wo541075754/article/details/52174900
spring与springboot中,如何在static方法里使用自动注入的属性
标签:blog fresh ack param 参考 静态 new value class
原文地址:https://www.cnblogs.com/BobXie85/p/8745705.html