gateway tomcat去除

This commit is contained in:
2025-12-22 17:03:37 +08:00
parent e09817015e
commit b023bec261
55 changed files with 1926 additions and 260 deletions

View File

@@ -6,9 +6,6 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.xyzh.common.auth.config.SecurityConfig;
import org.xyzh.common.auth.config.WebMvcConfig;
import org.xyzh.common.auth.config.GatewayAuthConfig;
/**
* @description Gateway 网关启动类
@@ -25,11 +22,12 @@ import org.xyzh.common.auth.config.GatewayAuthConfig;
"org.xyzh.common" // 公共模块(包括 common-auth
},
excludeFilters = {
// 排除 Spring MVC 相关配置,Gateway 使用 WebFlux
@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {
SecurityConfig.class, // Spring MVC Security配置
WebMvcConfig.class, // Spring MVC配置
GatewayAuthConfig.class // 微服务Gateway模式配置使用Servlet Filter
// 使用正则表达式排除 Spring MVC 相关配置,避免加载 WebMvcConfigurer 类
@ComponentScan.Filter(type = FilterType.REGEX, pattern = {
"org\\.xyzh\\.common\\.auth\\.config\\.SecurityConfig",
"org\\.xyzh\\.common\\.auth\\.config\\.WebMvcConfig",
"org\\.xyzh\\.common\\.auth\\.config\\.GatewayAuthConfig",
"org\\.xyzh\\.common\\.utils\\.config\\.FastJsonConfiguration"
})
}
)

View File

@@ -131,27 +131,32 @@ public class AuthGlobalFilter implements GlobalFilter, Ordered {
}
/**
* 从请求头中提取 Token
* 从请求头或URL参数中提取 Token
*/
private String extractToken(ServerHttpRequest request) {
// 1. 优先从请求头获取
List<String> headers = request.getHeaders().get(authProperties.getTokenHeader());
if (headers == null || headers.isEmpty()) {
return null;
if (headers != null && !headers.isEmpty()) {
String header = headers.get(0);
if (StringUtils.hasText(header)) {
// 支持 Bearer 前缀
String prefix = authProperties.getTokenPrefix();
if (StringUtils.hasText(prefix) && header.startsWith(prefix)) {
return header.substring(prefix.length()).trim();
}
// 也支持直接传递 Token不带前缀
return header.trim();
}
}
String header = headers.get(0);
if (!StringUtils.hasText(header)) {
return null;
// 2. 从URL参数获取用于WebSocket连接
String tokenParam = request.getQueryParams().getFirst("token");
if (StringUtils.hasText(tokenParam)) {
log.debug("从URL参数获取Token");
return tokenParam.trim();
}
// 支持 Bearer 前缀
String prefix = authProperties.getTokenPrefix();
if (StringUtils.hasText(prefix) && header.startsWith(prefix)) {
return header.substring(prefix.length()).trim();
}
// 也支持直接传递 Token不带前缀
return header.trim();
return null;
}
/**

View File

@@ -92,6 +92,14 @@ spring:
filters:
- StripPrefix=1
# ==================== 工单服务 WebSocket 路由 ====================
- id: workcase-websocket
uri: lb:ws://workcase-service
predicates:
- Path=/urban-lifeline/workcase/ws/**
filters:
- StripPrefix=1
# ==================== 工单服务路由 ====================
- id: workcase-service
uri: lb://workcase-service