Selaa lähdekoodia

租户端解决bean重复注入启动报错问题

xgb 2 viikkoa sitten
vanhempi
commit
ada6b01c7e

+ 0 - 2
fs-admin-saas/src/main/java/com/fs/FSAdminSaasApplication.java

@@ -1,6 +1,5 @@
 package com.fs;
 package com.fs;
 
 
-import com.fs.config.OverridingBeanNameGenerator;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
@@ -17,7 +16,6 @@ import org.springframework.transaction.annotation.Transactional;
 @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, RedissonAutoConfiguration.class})
 @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, RedissonAutoConfiguration.class})
 @ComponentScan(
 @ComponentScan(
     basePackages = "com.fs",
     basePackages = "com.fs",
-    nameGenerator = OverridingBeanNameGenerator.class,
     excludeFilters = {
     excludeFilters = {
         @ComponentScan.Filter(type = FilterType.REGEX, pattern = {
         @ComponentScan.Filter(type = FilterType.REGEX, pattern = {
             "com\\.fs\\.framework\\.service\\.PermissionService",
             "com\\.fs\\.framework\\.service\\.PermissionService",

+ 0 - 19
fs-admin-saas/src/main/java/com/fs/config/FullQualifiedBeanNameGenerator.java

@@ -1,19 +0,0 @@
-package com.fs.config;
-
-import org.springframework.beans.factory.config.BeanDefinition;
-import org.springframework.context.annotation.AnnotationBeanNameGenerator;
-
-/**
- * 使用全限定类名作为bean名称,避免不同包下同名类的bean冲突
- */
-public class FullQualifiedBeanNameGenerator extends AnnotationBeanNameGenerator {
-
-    @Override
-    protected String buildDefaultBeanName(BeanDefinition definition) {
-        String beanClassName = definition.getBeanClassName();
-        if (beanClassName != null) {
-            return beanClassName;
-        }
-        return super.buildDefaultBeanName(definition);
-    }
-}

+ 0 - 30
fs-admin-saas/src/main/java/com/fs/config/OverridingBeanNameGenerator.java

@@ -1,30 +0,0 @@
-package com.fs.config;
-
-import org.springframework.beans.factory.config.BeanDefinition;
-import org.springframework.beans.factory.support.BeanDefinitionRegistry;
-import org.springframework.context.annotation.AnnotationBeanNameGenerator;
-
-/**
- * 自定义BeanName生成器:对冲突的bean使用全限定名,其他保持默认行为
- * 解决fs-framework和fs-service中同名类的冲突问题
- */
-public class OverridingBeanNameGenerator extends AnnotationBeanNameGenerator {
-
-    @Override
-    public String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) {
-        // 先按默认逻辑生成名称
-        String beanName = super.generateBeanName(definition, registry);
-        
-        // 如果已存在同名bean但来自不同类,使用全限定名避免冲突
-        if (registry.containsBeanDefinition(beanName)) {
-            BeanDefinition existingDef = registry.getBeanDefinition(beanName);
-            String existingClass = existingDef.getBeanClassName();
-            String newClass = definition.getBeanClassName();
-            if (existingClass != null && newClass != null && !existingClass.equals(newClass)) {
-                // 冲突:使用全限定类名作为bean名称
-                return newClass;
-            }
-        }
-        return beanName;
-    }
-}

+ 0 - 45
fs-admin-saas/src/main/java/com/fs/config/RedissonConfig.java

@@ -1,45 +0,0 @@
-package com.fs.config;
-
-import org.redisson.Redisson;
-import org.redisson.api.RedissonClient;
-import org.redisson.config.Config;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-/**
- * 手动配置RedissonClient,仅用于分布式锁。
- * 排除RedissonAutoConfiguration后,避免Redisson接管RedisTemplate的连接工厂。
- */
-@Configuration
-@ConditionalOnProperty(name = "spring.redis.host")
-public class RedissonConfig {
-
-    @Value("${spring.redis.host:localhost}")
-    private String host;
-
-    @Value("${spring.redis.port:6379}")
-    private int port;
-
-    @Value("${spring.redis.password:}")
-    private String password;
-
-    @Value("${spring.redis.database:0}")
-    private int database;
-
-    @Bean(destroyMethod = "shutdown")
-    public RedissonClient redissonClient() {
-        Config config = new Config();
-        String address = "redis://" + host + ":" + port;
-        config.useSingleServer()
-                .setAddress(address)
-                .setDatabase(database)
-                .setConnectionMinimumIdleSize(1)
-                .setConnectionPoolSize(4);
-        if (password != null && !password.isEmpty()) {
-            config.useSingleServer().setPassword(password);
-        }
-        return Redisson.create(config);
-    }
-}

+ 0 - 107
fs-service/src/main/java/com/fs/company/aspectj/CallbackIpCheckAspect.java

@@ -1,107 +0,0 @@
-package com.fs.company.aspectj;
-
-import com.alibaba.fastjson.JSONObject;
-import com.fs.aicall.utils.StringUtils;
-import com.fs.common.annotation.CallbackIpCheck;
-import com.fs.common.utils.IpUtil;
-import com.fs.company.mapper.CompanyConfigMapper;
-import com.fs.company.util.IpCheckUtil;
-import com.fs.company.vo.CidConfigVO;
-import com.fs.system.domain.SysConfig;
-import com.fs.system.mapper.SysConfigMapper;
-import org.aspectj.lang.ProceedingJoinPoint;
-import org.aspectj.lang.annotation.Around;
-import org.aspectj.lang.annotation.Aspect;
-import org.aspectj.lang.annotation.Pointcut;
-import org.aspectj.lang.reflect.MethodSignature;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-import org.springframework.web.context.request.RequestContextHolder;
-import org.springframework.web.context.request.ServletRequestAttributes;
-
-import javax.servlet.http.HttpServletRequest;
-import java.lang.reflect.Method;
-
-/**
- * 回调IP校验切面
- * <p>
- * 拦截所有标注了 @CallbackIpCheck 的方法,自动完成:
- * 1. 从方法参数中提取 companyId
- * 2. 查询 company_config 获取配置(如 cId.config)
- * 3. 解析 CidPhoneConfig 获取 legalIPs
- * 4. 校验请求来源IP是否在合法列表中
- * 5. 不合法则阻断请求
- * </p>
- *
- * @author MixLiu
- */
-@Aspect
-@Component
-public class CallbackIpCheckAspect {
-
-    private static final Logger log = LoggerFactory.getLogger(CallbackIpCheckAspect.class);
-
-    @Autowired
-    private CompanyConfigMapper companyConfigMapper;
-    @Autowired
-    private SysConfigMapper sysConfigMapper;
-
-    @Pointcut("@annotation(com.fs.common.annotation.CallbackIpCheck)")
-    public void ipCheckPointCut() {
-    }
-
-    @Around("ipCheckPointCut()")
-    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
-        // 获取注解
-        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
-        Method method = signature.getMethod();
-        CallbackIpCheck annotation = method.getAnnotation(CallbackIpCheck.class);
-
-        // 获取当前请求
-        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
-        if (attributes == null) {
-            throw new IllegalStateException("CallbackIpCheck: 无法获取当前请求上下文");
-        }
-        HttpServletRequest request = attributes.getRequest();
-        String clientIp = IpUtil.getRequestIp(request);
-
-        // 查询配置
-        String configKey = annotation.configKey();
-        SysConfig sysConfig = sysConfigMapper.selectConfigByConfigKey(configKey);
-        if(null == sysConfig || StringUtils.isBlank(sysConfig.getConfigValue())){
-            log.error("CallbackIpCheck: 未找到配置,  configKey={}, 请求IP: {}",
-                    configKey, clientIp);
-            throw new IllegalArgumentException("CallbackIpCheck: 未找到公司配置");
-        }
-
-        CidConfigVO cidConf;
-        try {
-            cidConf = JSONObject.parseObject(sysConfig.getConfigValue(), CidConfigVO.class);
-        } catch (Exception e) {
-            log.error("CallbackIpCheck: 配置JSON解析失败,  configValue={}",
-                    sysConfig.getConfigValue(), e);
-            throw new IllegalArgumentException("CallbackIpCheck: 配置解析异常");
-        }
-
-        String legalIPs = cidConf.getLegalIPs();
-
-        // 校验IP
-        if (!IpCheckUtil.isIpInList(clientIp, legalIPs)) {
-            log.warn("非法回调来源IP: {}, legalIPs: {}", clientIp, legalIPs);
-            // 根据目标方法的返回类型返回对应的错误响应
-            Class<?> returnType = method.getReturnType();
-            if (returnType == String.class) {
-                return "illegal IP";
-            }
-            // 非String返回类型则抛异常,由全局异常处理器处理
-            throw new SecurityException("非法IP来源,请求IP: " + clientIp);
-        }
-
-        // IP校验通过,放行
-        return joinPoint.proceed();
-    }
-
-
-}

+ 0 - 47
fs-service/src/main/java/com/fs/company/aspectj/LiveControllerAspect.java

@@ -1,47 +0,0 @@
-package com.fs.company.aspectj;
-
-import cn.hutool.core.util.ObjectUtil;
-import com.fs.live.domain.Live;
-import com.fs.live.service.ILiveService;
-import org.aspectj.lang.JoinPoint;
-import org.aspectj.lang.annotation.AfterReturning;
-import org.aspectj.lang.annotation.Aspect;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
-import org.springframework.stereotype.Component;
-
-@Aspect
-@Component
-@ConditionalOnClass(name = "com.fs.company.controller.live.LiveController")
-public class LiveControllerAspect {
-
-    private static final Logger logger = LoggerFactory.getLogger(LiveControllerAspect.class);
-
-    @Autowired
-    private ILiveService liveService;
-
-    @AfterReturning(pointcut = "execution(* com.fs.company.controller.live.LiveController.add(..)) || " +
-            "execution(* com.fs.company.controller.live.LiveController.finishLive(..)) || " +
-            "execution(* com.fs.company.controller.live.LiveController.copyLive(..)) || " +
-            "execution(* com.fs.company.controller.live.LiveController.handleShelfOrUn(..)) || " +
-            "execution(* com.fs.company.controller.live.LiveController.handleDeleteSelected(..)) || " +
-            "execution(* com.fs.company.controller.live.LiveController.edit(..)) || " +
-            "execution(* com.fs.company.controller.live.LiveController.remove(..)) || " +
-            "execution(* com.fs.company.controller.live.LiveController.startLive(..))",
-            returning = "result")
-    public void afterLiveControllerMethodExecution(JoinPoint joinPoint,Object result) {
-        String methodName = joinPoint.getSignature().getName();
-        Object[] args = joinPoint.getArgs();
-        liveService.asyncToCache();
-        if (args[0] instanceof Live) {
-            Live live = (Live) args[0];
-            if (ObjectUtil.isNotEmpty(live) && ObjectUtil.isNotEmpty(live.getLiveId())){
-                liveService.asyncToCacheLiveDetail(live.getLiveId());
-            }
-        }
-        logger.info("后台直播间列表变更");
-
-    }
-}