From 24681c81c09022f584a57006f2534b5f74723414 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期二, 30 六月 2026 09:27:31 +0800
Subject: [PATCH] 初始化项目
---
yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/config/YudaoTenantAutoConfiguration.java | 70 +++++++++++++++++++++++++++--------
1 files changed, 54 insertions(+), 16 deletions(-)
diff --git a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/config/YudaoTenantAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/config/YudaoTenantAutoConfiguration.java
index fa252c4..b5f70aa 100644
--- a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/config/YudaoTenantAutoConfiguration.java
+++ b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/config/YudaoTenantAutoConfiguration.java
@@ -30,6 +30,7 @@
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.redis.cache.BatchStrategies;
import org.springframework.data.redis.cache.RedisCacheConfiguration;
@@ -42,8 +43,11 @@
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
+import org.springframework.web.util.pattern.PathPattern;
import java.util.*;
+
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
@AutoConfiguration
@ConditionalOnProperty(prefix = "yudao.tenant", value = "enable", matchIfMissing = true) // 鍏佽浣跨敤 yudao.tenant.enable=false 绂佺敤澶氱鎴�
@@ -125,6 +129,7 @@
*
* @return 蹇界暐绉熸埛鐨� URL 闆嗗悎
*/
+ @SuppressWarnings("removal")
private Set<String> getTenantIgnoreUrls() {
Set<String> ignoreUrls = new HashSet<>();
// 鑾峰緱鎺ュ彛瀵瑰簲鐨� HandlerMethod 闆嗗悎
@@ -139,35 +144,50 @@
continue;
}
// 娣诲姞鍒板拷鐣ョ殑 URL 涓�
- ignoreUrls.addAll(entry.getKey().getPatternValues());
+ if (entry.getKey().getPatternsCondition() != null) {
+ ignoreUrls.addAll(entry.getKey().getPatternsCondition().getPatterns());
+ }
+ if (entry.getKey().getPathPatternsCondition() != null) {
+ ignoreUrls.addAll(
+ convertList(entry.getKey().getPathPatternsCondition().getPatterns(), PathPattern::getPatternString));
+ }
}
return ignoreUrls;
}
// ========== MQ ==========
- @Bean
- public TenantRedisMessageInterceptor tenantRedisMessageInterceptor() {
- return new TenantRedisMessageInterceptor();
+ @Configuration(proxyBeanMethods = false)
+ @ConditionalOnClass(name = "cn.iocoder.yudao.framework.mq.redis.core.interceptor.RedisMessageInterceptor")
+ public static class TenantRedisMQConfiguration {
+
+ @Bean
+ public TenantRedisMessageInterceptor tenantRedisMessageInterceptor() {
+ return new TenantRedisMessageInterceptor();
+ }
+
}
- @Bean
+ @Configuration(proxyBeanMethods = false)
@ConditionalOnClass(name = "org.springframework.amqp.rabbit.core.RabbitTemplate")
- public TenantRabbitMQInitializer tenantRabbitMQInitializer() {
- return new TenantRabbitMQInitializer();
+ public static class TenantRabbitMQConfiguration {
+
+ @Bean
+ public TenantRabbitMQInitializer tenantRabbitMQInitializer() {
+ return new TenantRabbitMQInitializer();
+ }
+
}
- @Bean
+ @Configuration(proxyBeanMethods = false)
@ConditionalOnClass(name = "org.apache.rocketmq.spring.core.RocketMQTemplate")
- public TenantRocketMQInitializer tenantRocketMQInitializer() {
- return new TenantRocketMQInitializer();
- }
+ public static class TenantRocketMQConfiguration {
- // ========== Job ==========
+ @Bean
+ public TenantRocketMQInitializer tenantRocketMQInitializer() {
+ return new TenantRocketMQInitializer();
+ }
- @Bean
- public TenantJobAspect tenantJobAspect(TenantFrameworkService tenantFrameworkService) {
- return new TenantJobAspect(tenantFrameworkService);
}
// ========== Redis ==========
@@ -183,7 +203,25 @@
RedisCacheWriter cacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(connectionFactory,
BatchStrategies.scan(yudaoCacheProperties.getRedisScanBatchSize()));
// 鍒涘缓 TenantRedisCacheManager 瀵硅薄
- return new TenantRedisCacheManager(cacheWriter, redisCacheConfiguration, tenantProperties.getIgnoreCaches());
+ TenantRedisCacheManager cacheManager = new TenantRedisCacheManager(cacheWriter, redisCacheConfiguration,
+ tenantProperties.getIgnoreCaches());
+ // 寮�鍚簨鍔℃劅鐭ワ細@Transactional 鏂规硶鍐呯殑 @CacheEvict / @CachePut 鑷姩寤惰繜鍒� afterCommit锛�
+ // 閬垮厤浜嬪姟鏈彁浜ゅ氨娓呯紦瀛樿骞跺彂璇荤┛鍐欒剰鍊硷紱鏃犱簨鍔℃椂绔嬪嵆鐢熸晥锛岃涓轰笉鍙�
+ cacheManager.setTransactionAware(true);
+ return cacheManager;
+ }
+
+ // ========== Job ==========
+
+ @Configuration(proxyBeanMethods = false)
+ @ConditionalOnClass(name = "cn.iocoder.yudao.framework.quartz.core.handler.JobHandler")
+ public static class TenantJobConfiguration {
+
+ @Bean
+ public TenantJobAspect tenantJobAspect(TenantFrameworkService tenantFrameworkService) {
+ return new TenantJobAspect(tenantFrameworkService);
+ }
+
}
}
--
Gitblit v1.9.3