mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 12:56:28 +08:00
拦截器新增init方法
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
## 日常更新
|
||||
|
||||
- 2025-03-04:拦截器新增init方法,用来做一些初始化工作
|
||||
- 2025-02-27:新增token校验,com.gitee.sop.gateway.interceptor.internal.TokenValidateInterceptor.checkToken
|
||||
- 2025-02-20:修复Linux环境下启动报错,加载i18n问题;优化新增接口注册保存逻辑
|
||||
- 2025-02-19:升级fastmybatis到3.0.16
|
||||
|
@@ -2,6 +2,8 @@ package com.gitee.sop.gateway.interceptor;
|
||||
|
||||
import com.gitee.sop.gateway.common.ApiInfoDTO;
|
||||
import com.gitee.sop.gateway.request.ApiRequestContext;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
/**
|
||||
* 路由拦截器
|
||||
@@ -10,6 +12,16 @@ import com.gitee.sop.gateway.request.ApiRequestContext;
|
||||
*/
|
||||
public interface RouteInterceptor {
|
||||
|
||||
/**
|
||||
* 初始化,spring容器启动后执行。
|
||||
*
|
||||
* @param applicationContext spring上下文
|
||||
* @param environment spring环境变量
|
||||
*/
|
||||
default void init(ApplicationContext applicationContext, Environment environment) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 在路由转发前执行,签名校验通过后会立即执行此方法
|
||||
* <pre>
|
||||
|
@@ -30,6 +30,8 @@ import org.apache.dubbo.common.utils.ClassUtils;
|
||||
import org.apache.dubbo.rpc.RpcContext;
|
||||
import org.apache.dubbo.rpc.RpcContextAttachment;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -73,6 +75,11 @@ public class RouteServiceImpl implements RouteService {
|
||||
@Autowired
|
||||
private Serde serde;
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
@Override
|
||||
public Response route(ApiRequestContext apiRequestContext) {
|
||||
ApiRequest apiRequest = apiRequestContext.getApiRequest();
|
||||
@@ -259,6 +266,10 @@ public class RouteServiceImpl implements RouteService {
|
||||
routeInterceptors = new ArrayList<>();
|
||||
}
|
||||
routeInterceptors.sort(Comparator.comparing(RouteInterceptor::getOrder));
|
||||
|
||||
for (RouteInterceptor routeInterceptor : routeInterceptors) {
|
||||
routeInterceptor.init(applicationContext, environment);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user