[重大更新] 使用 spring 新特性 HttpServiceClient 替代 Dubbo 降低框架使用难度(半成本 数据权限不好使)

This commit is contained in:
疯狂的狮子Li
2026-03-20 19:56:09 +08:00
parent 9cd198d99d
commit b6d2274b53
127 changed files with 1894 additions and 1496 deletions

View File

@@ -62,7 +62,7 @@ public class AuthFilter implements WebMvcConfigurer {
}
})))
.addPathPatterns("/**")
.excludePathPatterns("/favicon.ico", "/actuator", "/actuator/**", "/resource/sse");
.excludePathPatterns("/favicon.ico", "/actuator", "/actuator/**", "/resource/sse" , "/error");
}
/**

View File

@@ -2,13 +2,19 @@ package org.dromara.gateway.handler;
import cn.dev33.satoken.exception.NotLoginException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.constant.HttpStatus;
import org.dromara.common.core.domain.R;
import org.dromara.common.json.utils.JsonUtils;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.server.ResponseStatusException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
/**
* 网关统一异常处理
*
@@ -19,23 +25,34 @@ import org.springframework.web.server.ResponseStatusException;
public class GatewayExceptionHandler {
@ExceptionHandler(NotLoginException.class)
public R<Void> handleNotLogin(HttpServletRequest request, NotLoginException ex) {
public void handleNotLogin(HttpServletRequest request, HttpServletResponse response, NotLoginException ex) throws IOException {
log.warn("[网关认证失败]请求路径:{},异常信息:{}", request.getRequestURI(), ex.getMessage());
return R.fail(HttpStatus.UNAUTHORIZED, ex.getMessage());
writeJson(response, HttpStatus.UNAUTHORIZED, ex.getMessage());
}
@ExceptionHandler(Throwable.class)
public R<Void> handle(HttpServletRequest request, Throwable ex) {
public void handle(HttpServletRequest request, HttpServletResponse response, Throwable ex) throws IOException {
int code;
String msg;
if ("NotFoundException".equals(ex.getClass().getSimpleName())) {
code = HttpStatus.NOT_FOUND;
msg = "服务未找到";
} else if (ex instanceof ResponseStatusException responseStatusException) {
code = responseStatusException.getStatusCode().value();
msg = responseStatusException.getMessage();
} else {
code = HttpStatus.ERROR;
msg = "内部服务器错误";
}
log.error("[网关异常处理]请求路径:{},异常信息:{}", request.getRequestURI(), ex.getMessage(), ex);
return R.fail(msg);
writeJson(response, code, msg);
}
private void writeJson(HttpServletResponse response, int code, String msg) throws IOException {
response.setStatus(code);
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
response.getWriter().write(JsonUtils.toJsonString(R.fail(code, msg)));
}
}