Skip to content

Commit f7ed2bb

Browse files
authored
chore: 更新租户忽略注解 (#9)
1 parent 88d1102 commit f7ed2bb

File tree

3 files changed

+11
-2
lines changed
  • continew-starter-extension/continew-starter-extension-tenant

3 files changed

+11
-2
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@
2727
@Target({ElementType.TYPE, ElementType.METHOD})
2828
@Retention(RetentionPolicy.RUNTIME)
2929
@Documented
30-
public @interface TenantDataSourceIgnore {
30+
public @interface TenantIgnore {
3131
}

continew-starter-extension/continew-starter-extension-tenant/continew-starter-extension-tenant-core/src/main/java/top/continew/starter/extension/tenant/autoconfigure/TenantInterceptor.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
import jakarta.servlet.http.HttpServletRequest;
2020
import jakarta.servlet.http.HttpServletResponse;
2121
import org.springframework.core.Ordered;
22+
import org.springframework.web.method.HandlerMethod;
2223
import org.springframework.web.servlet.HandlerInterceptor;
24+
import top.continew.starter.extension.tenant.annotation.TenantIgnore;
2325
import top.continew.starter.extension.tenant.config.TenantProvider;
2426
import top.continew.starter.extension.tenant.context.TenantContextHolder;
2527

@@ -41,6 +43,13 @@ public TenantInterceptor(TenantProperties tenantProperties, TenantProvider tenan
4143

4244
@Override
4345
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
46+
if (handler instanceof HandlerMethod) {
47+
HandlerMethod handlerMethod = (HandlerMethod)handler;
48+
TenantIgnore customAnnotation = handlerMethod.getMethodAnnotation(TenantIgnore.class);
49+
if (customAnnotation != null) {
50+
return true;
51+
}
52+
}
4453
String tenantId = request.getHeader(tenantProperties.getTenantIdHeader());
4554
TenantContextHolder.setContext(tenantProvider.getByTenantId(tenantId, true));
4655
return true;

continew-starter-extension/continew-starter-extension-tenant/continew-starter-extension-tenant-mp/src/main/java/top/continew/starter/extension/tenant/handler/datasource/TenantDataSourceAdvisor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private Pointcut buildPointcut() {
6767
AspectJExpressionPointcut cut = new AspectJExpressionPointcut();
6868
cut.setExpression("""
6969
execution(* *..controller..*(..))
70-
&& !@annotation(top.continew.starter.extension.tenant.annotation.TenantDataSourceIgnore)
70+
&& !@annotation(top.continew.starter.extension.tenant.annotation.TenantIgnore)
7171
""");
7272
return new ComposablePointcut((Pointcut)cut);
7373
}

0 commit comments

Comments
 (0)