spring-cloud/yudao-framework
温艺伟 f12162e7ff 使用外部中间件时,如:金蝶、东方通 在不重启整个中间件的情况下,二次部署或多个服务同时部署在一个虚拟机下(JVM) IdTypeEnvironmentPostProcessor.setIdType 会将一个IdType对象put进SystemPropertiesPropertySource,而SystemPropertiesPropertySource在整个JVM中是共用的,导致两处问题:
报错信息:org.springframework.core.convert.ConverterNotFoundException:
        No converter found capable of converting from type [com.baomidou.mybatisplus.annotation.IdType] to type [com.baomidou.mybatisplus.annotation.IdType]
    问题一:IdTypeEnvironmentPostProcessor.getIdType 中 environment.getProperty(ID_TYPE_KEY, IdType.class) 获取到了上一次部署应用时的 IdType 对象,而上一次的 IdType 对象,和本次部署时 IdType.class 的类加载器不一致,导致报错;
    问题二:org.springframework.boot.context.properties.bind.BindConverter.convert 中,delegate.canConvert 返回的都是false,最终:throw (failure != null) ? failure : new ConverterNotFoundException(sourceType, targetType);
    原因分析:
    首先 ConfigurableEnvironment
        ConfigurableEnvironment.getProperty(...) 的查找顺序是分层次的:
        1、命令行参数(CommandLinePropertySource,即 --key=value)
        2、Java 系统属性(System.getProperties(),对应 SystemPropertiesPropertySource)
        3、操作系统环境变量(System.getenv(),对应 SystemEnvironmentPropertySource)
        4、application.yml / application.properties(OriginTrackedMapPropertySource)
        5、默认属性(DefaultPropertiesPropertySource)
    其次:Spring 的属性绑定用到了 ConfigurationPropertySource
        ConfigurationPropertySource:
            它是 Spring Boot 2.x 以后引入的抽象,表示配置属性的来源。
            比如:
            .properties / .yml 文件,
            系统属性(System.getProperties()),
            环境变量(System.getenv()),
            甚至 Nacos、Apollo 这样的远程配置中心。
            它统一成 ConfigurationPropertySource 接口,Spring Boot 就能用同一套逻辑去读取配置。
        和 ConfigurableEnvironment 的关系
            ConfigurableEnvironment 内部持有一系列 PropertySource。
            Spring Boot 启动时会把这些 PropertySource 适配成 ConfigurationPropertySource,
            这样属性绑定器(Binder)就可以从中读取配置值。
            也就是说:
            environment.getProperty("my.key") 读出来的值,
            和 Binder 里 ConfigurationPropertySource 提供的值,
            本质上是同一批配置源,只是走的 API 不一样。
        导致的问题:org.springframework.boot.context.properties.bind.BindConverter.convert 的参数:Object source, TypeDescriptor sourceType, TypeDescriptor targetType
            source 是上一次部署时的 IdType 对象
            sourceType 的类加载器 (sourceType.getType().getClassLoader()) 与 targetType 的类加载器 (targetType.getType().getClassLoader())不一致,抛出:ConverterNotFoundException

        org.springframework.boot.context.properties.bind.BindConverter.convert:
        private Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
            ConversionException failure = null;
            for (ConversionService delegate : this.delegates) {
                try {
                    if (delegate.canConvert(sourceType, targetType)) {
                        return delegate.convert(source, sourceType, targetType);
                    }
                }
                catch (ConversionException ex) {
                    if (failure == null && ex instanceof ConversionFailedException) {
                        failure = ex;
                    }
                }
            }
            throw (failure != null) ? failure : new ConverterNotFoundException(sourceType, targetType);
        }
2025-09-01 11:45:37 +08:00
..
yudao-common Merge branch 'master-jdk17' of https://gitee.com/zhijiantianya/yudao-cloud 2025-08-31 10:25:53 +08:00
yudao-spring-boot-starter-biz-data-permission Merge branch 'master-jdk17' of https://gitee.com/zhijiantianya/yudao-cloud 2025-07-27 19:43:17 +08:00
yudao-spring-boot-starter-biz-ip 【同步】BOOT 和 CLOUD 的功能(所有) 2025-01-24 20:42:23 +08:00
yudao-spring-boot-starter-biz-tenant 【同步】BOOT 和 CLOUD 的功能 2025-08-31 10:29:26 +08:00
yudao-spring-boot-starter-env Merge branch 'master-jdk17' of https://gitee.com/zhijiantianya/yudao-cloud 2025-08-17 11:31:16 +08:00
yudao-spring-boot-starter-excel Merge branch 'master-jdk17' of https://gitee.com/zhijiantianya/yudao-cloud 2025-07-27 19:43:17 +08:00
yudao-spring-boot-starter-job Merge branch 'master-jdk17' of https://gitee.com/zhijiantianya/yudao-cloud 2025-08-29 20:22:25 +08:00
yudao-spring-boot-starter-monitor Merge branch 'master-jdk17' of https://gitee.com/zhijiantianya/yudao-cloud 2025-08-24 15:46:52 +08:00
yudao-spring-boot-starter-mq feat:【IoT 物联网】新版本同步 2025-08-30 09:34:40 +08:00
yudao-spring-boot-starter-mybatis 使用外部中间件时,如:金蝶、东方通 在不重启整个中间件的情况下,二次部署或多个服务同时部署在一个虚拟机下(JVM) IdTypeEnvironmentPostProcessor.setIdType 会将一个IdType对象put进SystemPropertiesPropertySource,而SystemPropertiesPropertySource在整个JVM中是共用的,导致两处问题: 2025-09-01 11:45:37 +08:00
yudao-spring-boot-starter-protection Merge branch 'master-jdk17' of https://gitee.com/zhijiantianya/yudao-cloud 2025-08-30 11:18:33 +08:00
yudao-spring-boot-starter-redis 【依赖】解决 redisson-spring-boot-starter 升级到 3.32.0 后的 Tuple NoClassDefFoundError 报错 2024-07-17 19:27:14 +08:00
yudao-spring-boot-starter-rpc 【优化】支持登陆用户,直接读取昵称、部门等信息,也支持自定义字段 2024-04-07 19:51:24 +08:00
yudao-spring-boot-starter-security Merge branch 'master-jdk17' of https://gitee.com/zhijiantianya/yudao-cloud 2025-08-31 10:25:53 +08:00
yudao-spring-boot-starter-test Merge branch 'master-jdk17' of https://gitee.com/zhijiantianya/yudao-cloud 2024-10-01 14:52:28 +08:00
yudao-spring-boot-starter-web Merge branch 'master-jdk17' of https://gitee.com/zhijiantianya/yudao-cloud 2025-08-29 20:22:25 +08:00
yudao-spring-boot-starter-websocket 【同步】BOOT 和 CLOUD 的功能 2025-03-16 17:33:43 +08:00
pom.xml 【重构】V2 操作日志转正,基于注解的可使用变量、可以自定义函数的通用操作日志组件 2024-04-04 02:13:36 +08:00