Administrator 1 jaar geleden
bovenliggende
commit
85b448f03e
1 gewijzigde bestanden met toevoegingen van 8 en 4 verwijderingen
  1. 8 4
      src/main/java/com/xiesx/fastboot/core/token/handle/TokenInterceptorHandler.java

+ 8 - 4
src/main/java/com/xiesx/fastboot/core/token/handle/TokenInterceptorHandler.java

@@ -12,7 +12,9 @@ import javax.servlet.http.HttpServletResponse;
 import com.alibaba.fastjson.JSONObject;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.Lazy;
+import org.springframework.stereotype.Component;
 import org.springframework.web.method.HandlerMethod;
 import org.springframework.web.servlet.HandlerInterceptor;
 import org.springframework.web.servlet.ModelAndView;
@@ -42,9 +44,11 @@ public class TokenInterceptorHandler implements HandlerInterceptor {
 
     private String key;
 
-    @Autowired
-    @Lazy
-    GoTokenAuthentication goTokenAuthentication;
+    static GoTokenAuthentication goTokenAuthentication;
+
+    private GoTokenAuthentication getGoTokenAuthentication(){
+        return goTokenAuthentication == null ? SpringHelper.getBean(GoTokenAuthentication.class) : goTokenAuthentication;
+    }
 
     /**
      * Controller执行之前,如果返回false,controller不执行
@@ -98,7 +102,7 @@ public class TokenInterceptorHandler implements HandlerInterceptor {
                         GoToken goToken = (GoToken)annotation2;
                         if(StringUtils.isNotEmpty(goToken.permissions())){
                             Long userId = Long.parseLong(claims.getOrDefault(TokenCfg.USERID, "").toString());
-                            goTokenAuthentication.authenticate(userId, goToken.permissions());
+                            getGoTokenAuthentication().authenticate(userId, goToken.permissions());
                         }
                     }
                 }