| | |
| | | package com.iailab.framework.tenant.config; |
| | | |
| | | import com.baomidou.dynamic.datasource.processor.DsProcessor; |
| | | import com.baomidou.dynamic.datasource.processor.DsSpelExpressionProcessor; |
| | | import com.iailab.framework.common.enums.WebFilterOrderEnum; |
| | | import com.iailab.framework.mybatis.core.util.MyBatisUtils; |
| | | import com.iailab.framework.redis.config.IailabCacheProperties; |
| | | import com.iailab.framework.tenant.core.aop.TenantIgnoreAspect; |
| | | import com.iailab.framework.tenant.core.db.TenantDatabaseInterceptor; |
| | | import com.iailab.framework.tenant.core.db.dynamic.TenantDsProcessor; |
| | | import com.iailab.framework.tenant.core.job.TenantJobAspect; |
| | | import com.iailab.framework.tenant.core.mq.rabbitmq.TenantRabbitMQInitializer; |
| | | import com.iailab.framework.tenant.core.mq.redis.TenantRedisMessageInterceptor; |
| | |
| | | // 需要加在首个,主要是为了在分页插件前面。这个是 MyBatis Plus 的规定 |
| | | MyBatisUtils.addInterceptor(interceptor, inner, 0); |
| | | return inner; |
| | | } |
| | | |
| | | @Bean |
| | | public DsProcessor dsProcessor( |
| | | // TenantFrameworkService tenantFrameworkService, |
| | | // DataSource dataSource, |
| | | // DefaultDataSourceCreator dataSourceCreator |
| | | ) { |
| | | // TenantDsProcessor tenantDsProcessor = new TenantDsProcessor(tenantFrameworkService, dataSourceCreator); |
| | | TenantDsProcessor tenantDsProcessor = new TenantDsProcessor(); |
| | | tenantDsProcessor.setNextProcessor(new DsSpelExpressionProcessor()); |
| | | return tenantDsProcessor; |
| | | } |
| | | |
| | | // ========== WEB ========== |
| | |
| | | @Primary // 引入租户时,tenantRedisCacheManager 为主 Bean |
| | | public RedisCacheManager tenantRedisCacheManager(RedisTemplate<String, Object> redisTemplate, |
| | | RedisCacheConfiguration redisCacheConfiguration, |
| | | IailabCacheProperties iailabCacheProperties) { |
| | | IailabCacheProperties iailabCacheProperties, |
| | | TenantProperties tenantProperties) { |
| | | // 创建 RedisCacheWriter 对象 |
| | | RedisConnectionFactory connectionFactory = Objects.requireNonNull(redisTemplate.getConnectionFactory()); |
| | | RedisCacheWriter cacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(connectionFactory, |
| | | BatchStrategies.scan(iailabCacheProperties.getRedisScanBatchSize())); |
| | | // 创建 TenantRedisCacheManager 对象 |
| | | return new TenantRedisCacheManager(cacheWriter, redisCacheConfiguration); |
| | | return new TenantRedisCacheManager(cacheWriter, redisCacheConfiguration, tenantProperties.getIgnoreCaches()); |
| | | } |
| | | } |