Skip to content

Commit

Permalink
chore: 更新租户忽略注解
Browse files Browse the repository at this point in the history
  • Loading branch information
xtanyu committed Dec 25, 2024
1 parent 88d1102 commit 192cecd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface TenantDataSourceIgnore {
public @interface TenantIgnore {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 192cecd

Please sign in to comment.