mirror of
https://github.com/continew-org/continew-starter.git
synced 2025-09-09 04:59:21 +08:00
chore: 更新租户忽略注解 (#9)
This commit is contained in:
@@ -27,5 +27,5 @@ import java.lang.annotation.*;
|
||||
@Target({ElementType.TYPE, ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface TenantDataSourceIgnore {
|
||||
public @interface TenantIgnore {
|
||||
}
|
@@ -19,7 +19,9 @@ package top.continew.starter.extension.tenant.autoconfigure;
|
||||
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 class TenantInterceptor implements HandlerInterceptor, Ordered {
|
||||
|
||||
@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;
|
||||
|
@@ -67,7 +67,7 @@ public class TenantDataSourceAdvisor extends AbstractPointcutAdvisor implements
|
||||
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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user