diff --git a/continew-starter-extension/continew-starter-extension-tenant/continew-starter-extension-tenant-core/src/main/java/top/continew/starter/extension/tenant/annotation/TenantDataSourceIgnore.java b/continew-starter-extension/continew-starter-extension-tenant/continew-starter-extension-tenant-core/src/main/java/top/continew/starter/extension/tenant/annotation/TenantIgnore.java similarity index 95% rename from continew-starter-extension/continew-starter-extension-tenant/continew-starter-extension-tenant-core/src/main/java/top/continew/starter/extension/tenant/annotation/TenantDataSourceIgnore.java rename to continew-starter-extension/continew-starter-extension-tenant/continew-starter-extension-tenant-core/src/main/java/top/continew/starter/extension/tenant/annotation/TenantIgnore.java index ddc6164..93c9db0 100644 --- a/continew-starter-extension/continew-starter-extension-tenant/continew-starter-extension-tenant-core/src/main/java/top/continew/starter/extension/tenant/annotation/TenantDataSourceIgnore.java +++ b/continew-starter-extension/continew-starter-extension-tenant/continew-starter-extension-tenant-core/src/main/java/top/continew/starter/extension/tenant/annotation/TenantIgnore.java @@ -27,5 +27,5 @@ @Target({ElementType.TYPE, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @Documented -public @interface TenantDataSourceIgnore { +public @interface TenantIgnore { } diff --git a/continew-starter-extension/continew-starter-extension-tenant/continew-starter-extension-tenant-core/src/main/java/top/continew/starter/extension/tenant/autoconfigure/TenantInterceptor.java b/continew-starter-extension/continew-starter-extension-tenant/continew-starter-extension-tenant-core/src/main/java/top/continew/starter/extension/tenant/autoconfigure/TenantInterceptor.java index c0e85aa..2068f0f 100644 --- a/continew-starter-extension/continew-starter-extension-tenant/continew-starter-extension-tenant-core/src/main/java/top/continew/starter/extension/tenant/autoconfigure/TenantInterceptor.java +++ b/continew-starter-extension/continew-starter-extension-tenant/continew-starter-extension-tenant-core/src/main/java/top/continew/starter/extension/tenant/autoconfigure/TenantInterceptor.java @@ -19,7 +19,9 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.springframework.core.Ordered; +import org.springframework.web.method.HandlerMethod; import org.springframework.web.servlet.HandlerInterceptor; +import top.continew.starter.extension.tenant.annotation.TenantIgnore; import top.continew.starter.extension.tenant.config.TenantProvider; import top.continew.starter.extension.tenant.context.TenantContextHolder; @@ -41,6 +43,13 @@ public TenantInterceptor(TenantProperties tenantProperties, TenantProvider tenan @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { + if (handler instanceof HandlerMethod) { + HandlerMethod handlerMethod = (HandlerMethod)handler; + TenantIgnore customAnnotation = handlerMethod.getMethodAnnotation(TenantIgnore.class); + if (customAnnotation != null) { + return true; + } + } String tenantId = request.getHeader(tenantProperties.getTenantIdHeader()); TenantContextHolder.setContext(tenantProvider.getByTenantId(tenantId, true)); return true; diff --git a/continew-starter-extension/continew-starter-extension-tenant/continew-starter-extension-tenant-mp/src/main/java/top/continew/starter/extension/tenant/handler/datasource/TenantDataSourceAdvisor.java b/continew-starter-extension/continew-starter-extension-tenant/continew-starter-extension-tenant-mp/src/main/java/top/continew/starter/extension/tenant/handler/datasource/TenantDataSourceAdvisor.java index 57f3c7c..88b530a 100644 --- a/continew-starter-extension/continew-starter-extension-tenant/continew-starter-extension-tenant-mp/src/main/java/top/continew/starter/extension/tenant/handler/datasource/TenantDataSourceAdvisor.java +++ b/continew-starter-extension/continew-starter-extension-tenant/continew-starter-extension-tenant-mp/src/main/java/top/continew/starter/extension/tenant/handler/datasource/TenantDataSourceAdvisor.java @@ -67,7 +67,7 @@ private Pointcut buildPointcut() { AspectJExpressionPointcut cut = new AspectJExpressionPointcut(); cut.setExpression(""" execution(* *..controller..*(..)) - && !@annotation(top.continew.starter.extension.tenant.annotation.TenantDataSourceIgnore) + && !@annotation(top.continew.starter.extension.tenant.annotation.TenantIgnore) """); return new ComposablePointcut((Pointcut)cut); }