|
@@ -5,21 +5,20 @@ import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor;
|
|
|
import com.usky.common.tenant.core.aop.TenantIgnoreAspect;
|
|
|
-import com.usky.common.tenant.core.db.TenantDatabaseInterceptor;
|
|
|
+import com.usky.common.tenant.core.db.TenantDatabaseHandler;
|
|
|
import com.usky.common.tenant.core.web.TenantContextWebFilter;
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
|
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
-
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
@Configuration
|
|
|
-@ConditionalOnProperty(prefix = "tenant", value = "enable", matchIfMissing = true) // 允许使用 yudao.tenant.enable=false 禁用多租户
|
|
|
+@ConditionalOnProperty(prefix = "tenant", value = "enable", matchIfMissing = true) // 允许使用 tenant.enable=treu 禁用多租户
|
|
|
@EnableConfigurationProperties(TenantProperties.class)
|
|
|
-public class UskyTenantAutoConfiguration {
|
|
|
+public class TenantAutoConfiguration {
|
|
|
|
|
|
|
|
|
// ========== AOP ==========
|
|
@@ -31,21 +30,32 @@ public class UskyTenantAutoConfiguration {
|
|
|
|
|
|
// ========== DB ==========
|
|
|
|
|
|
+ /**
|
|
|
+ * mybatis-plus 多组户配置
|
|
|
+ * @param properties
|
|
|
+ * @param interceptor
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Bean
|
|
|
public TenantLineInnerInterceptor tenantLineInnerInterceptor(TenantProperties properties,MybatisPlusInterceptor interceptor) {
|
|
|
- TenantLineInnerInterceptor inner = new TenantLineInnerInterceptor(new TenantDatabaseInterceptor(properties));
|
|
|
+ TenantLineInnerInterceptor inner = new TenantLineInnerInterceptor();
|
|
|
+ //多租户插件
|
|
|
+ inner.setTenantLineHandler(new TenantDatabaseHandler(properties));
|
|
|
+
|
|
|
// 添加到 interceptor 中
|
|
|
// 需要加在首个,主要是为了在分页插件前面。这个是 MyBatis Plus 的规定
|
|
|
-
|
|
|
List<InnerInterceptor> inners = new ArrayList<>(interceptor.getInterceptors());
|
|
|
inners.add(0, inner);
|
|
|
interceptor.setInterceptors(inners);
|
|
|
-
|
|
|
return inner;
|
|
|
}
|
|
|
|
|
|
- // ========== WEB ==========
|
|
|
|
|
|
+ /**
|
|
|
+ * 注册Web拦截器解析租户ID
|
|
|
+ * 通过{@link com.usky.common.tenant.core.context.TenantContextHolder} 传递给 {@link TenantDatabaseHandler}
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Bean
|
|
|
public FilterRegistrationBean<TenantContextWebFilter> tenantContextWebFilter() {
|
|
|
FilterRegistrationBean<TenantContextWebFilter> registrationBean = new FilterRegistrationBean<>();
|