Administrator 1 год назад
Родитель
Сommit
85b448f03e

+ 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());
                         }
                     }
                 }