多租户(forge-starter-tenant)
工程位置:forge-server/forge-framework/forge-starter-parent/forge-starter-tenant。Maven artifactId 是 forge-starter-tenant。src/main/java 里有 18 个 Java 文件。
引入
xml
<dependency>
<groupId>com.mdframe.forge</groupId>
<artifactId>forge-starter-tenant</artifactId>
</dependency>自动装配
META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports 登记了:
com.mdframe.forge.starter.tenant.config.TenantAutoConfiguration
配置属性
forge.business.datasource(com.mdframe.forge.starter.tenant.datasource.BusinessDataSourceProperties)
| 字段 | 类型 | 类内默认值 | 说明 |
|---|---|---|---|
enabled | boolean | false | 是否启用业务侧租户数据源能力。 |
tenantRoutingEnabledDefault | boolean | false | sys_config 未配置时是否默认启用租户路由。 |
forge.tenant(com.mdframe.forge.starter.tenant.config.TenantProperties)
| 字段 | 类型 | 类内默认值 | 说明 |
|---|---|---|---|
enabled | Boolean | true | 是否启用多租户。 |
column | String | "tenant_id" | 租户字段名。 |
ignoreTables | List<String> | 构造时预填平台表,见下表 | 忽略租户的表名列表。这些表不会自动添加租户条件。 |
ignoreSqlKeywords | List<String> | new ArrayList<>() | 忽略租户的 SQL 关键字。包含这些关键字的 SQL 不会添加租户条件。 |
strictMode | Boolean | true | 没有租户 ID 时是否抛异常。true 抛异常(严格模式),false 只记警告(宽松模式)。 |
autoDetectTenantColumn | Boolean | true | 是否自动检测租户字段。true 启动时扫描表结构,没有租户字段的表自动跳过过滤;false 只认 ignoreTables。 |
TenantProperties 构造函数会往 ignoreTables 预填这些平台表(源码注释:平台级表不按当前租户做 SQL 隔离,租户内授权由关联表控制):
sys_tenant、sys_resource、sys_client、sys_region_code、sys_api_config、sys_config_group、sys_excel_column_config、sys_excel_export_config、sys_file_storage_config、sys_job_log、sys_job_config、gen_datasource、gen_table、gen_table_column、worker_node、sys_id_sequence、ai_page_template。
类内默认值不是官方启动配置。各服务 application.yml 可以覆盖。
注解
@TenantBusinessDataSource
com.mdframe.forge.starter.tenant.datasource.TenantBusinessDataSource
没有成员。
源码类型清单
下面只列 forge-starter-tenant 自己的公开类型。
接口
com.mdframe.forge.starter.tenant.datasource.TenantBusinessDataSourceResolvercom.mdframe.forge.starter.tenant.datasource.TenantBusinessDataSourceScope
类
BusinessDataSourcePropertiesDefaultTenantLineHandlerIgnoreTenantAspectTenantAutoConfigurationTenantBusinessDataSourceAspectTenantBusinessDataSourceExecutorTenantBusinessDataSourceInfoTenantBusinessDataSourceTaskDecoratorTenantBusinessDataSourceTaskDecoratorPostProcessorTenantContextHolderTenantEntityTenantInterceptorTenantPropertiesTenantTableCheckerTenantUtil
