- name
SKILL.md
技能文件保留在发布者的仓库中。
在终端中粘贴复制的命令。它会把这个 SKILL.md 安装到对应的智能体中。
npx skills add rrezartprebreza/spring-boot-skills --skill multi-tenancy -a cursor -y在终端中粘贴复制的命令。它会把这个 SKILL.md 安装到对应的智能体中。
npx skills add rrezartprebreza/spring-boot-skills --skill multi-tenancy -a claude-code -y在终端中粘贴复制的命令。它会把这个 SKILL.md 安装到对应的智能体中。
npx skills add rrezartprebreza/spring-boot-skills --skill multi-tenancy -a codex -y在终端中粘贴复制的命令。它会把这个 SKILL.md 安装到对应的智能体中。
npx skills add rrezartprebreza/spring-boot-skills --skill multi-tenancy -a grok -y在 Grok Bot 聊天中发送复制的消息。Bot 会从 GitHub 获取这个 SKILL.md,并添加到你所有 Bot 共享的技能中。
Install this skill: https://github.com/rrezartprebreza/spring-boot-skills/tree/HEAD/skills/spring-boot-3/multi-tenancy来自发布者
Treat tenant identity as an authorization boundary, not a query convenience.
tenant_id: simplest operations, but every access path must enforce scope.X-Tenant-Id header by itself.finally; use Reactor Context for reactive flows.examples/good-tenant-filter.java and examples/bad-tenant-filter.java.The TenantOrderStore and schema implement tenant-scoped reads, creates, updates and deletes. This example uses blocking JDBC, a verified resource-server JWT and an active-tenant registry. It is not a database/schema-routing or reactive implementation. Preserve the application's existing ID types and isolation model rather than copying this UUID model indiscriminately.
Wire TenantScopeFilter into the security chain before
AuthorizationFilter (after bearer authentication and exception translation). Supply a
RequestMatcher for only the tenant-protected routes and a server-side predicate checking the
tenant registry. Instantiate the filter inside the chain configuration, or disable its servlet
auto-registration if it is a bean, so it does not run twice. Missing authentication is 401;
missing, disabled or unknown tenant membership is 403. Do not read a public tenant header.
The verified tenant_id claim must be issued under a trusted tenant-membership policy; where
revocation must take effect before token expiry, consult current membership as well as the
active-tenant registry. Background jobs must similarly re-authorize tenant activity/membership
at execution time. A captured ID is context propagation, not perpetual authorization.
TenantContext scopes work with try/finally cleanup, preserves nested scopes and provides tenant-qualified cache keys:
TenantId tenant = TenantAccess.resolve(authentication, tenantRegistry::isActive);
try (var scope = TenantContext.open(tenant)) {
store.find(orderId);
String key = TenantContext.orderCacheKey(orderId);
executor.execute(TenantContext.capture(() -> store.find(orderId)));
}
Open the tenant scope before invoking a separate transactional service proxy. The example
does not propagate a transaction or SecurityContext to the worker; it starts its own unit of
work. Do not use InheritableThreadLocal with pooled workers. Servlet async dispatches need
explicit context propagation too. Scope every list, join and native query, and include
tenant_id in child foreign keys. No Java repository wrapper protects against arbitrary
unscoped SQL: restrict database credentials and consider PostgreSQL row-level security as
defense in depth.
Verify same-ID records in two tenants, forbidden cross-tenant reads/updates/deletes, distinct cache keys, missing-context rejection, exception cleanup and sequential jobs on one worker.
The repository fixture targets Boot 3.5.16 with Java 17/21 and checks PostgreSQL 16 shared-schema access and blocking thread context; not Hibernate schema routing or Reactor. Check the coverage matrix before treating another minor version or an illustrative snippet as verified.
ThreadLocal - pooled threads can leak one tenant into another request.>
---name: multi-tenancydescription: >---# skills/spring-boot-3/multi-tenancy/SKILL.md常见问题
从发布者处下载 skills/spring-boot-3/multi-tenancy/SKILL.md,或复制路径后打开仓库。PlugMCP 只收录该技能,不托管文件。
发布者将它存放在 https://github.com/rrezartprebreza/spring-boot-skills。
Claude、Cursor、Codex 和 Grok Build 可以读取你从发布者仓库添加的 SKILL.md。在聊天中发送技能的 GitHub 文件夹链接,Grok Bot 就会安装它。