chore: 更新租户忽略注解 (#9)

This commit is contained in:
小熊
2024-12-25 17:23:37 +08:00
committed by GitHub
parent 88d11027dd
commit f7ed2bbfb0
3 changed files with 11 additions and 2 deletions

View File

@@ -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;

View File

@@ -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);
}