From f12162e7ff7c200e2a97c219d67547bf869c573f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B8=A9=E8=89=BA=E4=BC=9F?= <1036795720@qq.com> Date: Mon, 1 Sep 2025 11:45:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=A4=96=E9=83=A8=E4=B8=AD?= =?UTF-8?q?=E9=97=B4=E4=BB=B6=E6=97=B6=EF=BC=8C=E5=A6=82=EF=BC=9A=E9=87=91?= =?UTF-8?q?=E8=9D=B6=E3=80=81=E4=B8=9C=E6=96=B9=E9=80=9A=20=E5=9C=A8?= =?UTF-8?q?=E4=B8=8D=E9=87=8D=E5=90=AF=E6=95=B4=E4=B8=AA=E4=B8=AD=E9=97=B4?= =?UTF-8?q?=E4=BB=B6=E7=9A=84=E6=83=85=E5=86=B5=E4=B8=8B=EF=BC=8C=E4=BA=8C?= =?UTF-8?q?=E6=AC=A1=E9=83=A8=E7=BD=B2=E6=88=96=E5=A4=9A=E4=B8=AA=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=90=8C=E6=97=B6=E9=83=A8=E7=BD=B2=E5=9C=A8=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E8=99=9A=E6=8B=9F=E6=9C=BA=E4=B8=8B=EF=BC=88JVM?= =?UTF-8?q?=EF=BC=89=20=20IdTypeEnvironmentPostProcessor.setIdType=20?= =?UTF-8?q?=E4=BC=9A=E5=B0=86=E4=B8=80=E4=B8=AAIdType=E5=AF=B9=E8=B1=A1put?= =?UTF-8?q?=E8=BF=9BSystemPropertiesPropertySource=EF=BC=8C=E8=80=8CSystem?= =?UTF-8?q?PropertiesPropertySource=E5=9C=A8=E6=95=B4=E4=B8=AAJVM=E4=B8=AD?= =?UTF-8?q?=E6=98=AF=E5=85=B1=E7=94=A8=E7=9A=84=EF=BC=8C=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E4=B8=A4=E5=A4=84=E9=97=AE=E9=A2=98=EF=BC=9A=20=20=20=20=20?= =?UTF-8?q?=E6=8A=A5=E9=94=99=E4=BF=A1=E6=81=AF=EF=BC=9Aorg.springframewor?= =?UTF-8?q?k.core.convert.ConverterNotFoundException:=20=20=20=20=20=20=20?= =?UTF-8?q?=20=20No=20converter=20found=20capable=20of=20converting=20from?= =?UTF-8?q?=20type=20[com.baomidou.mybatisplus.annotation.IdType]=20to=20t?= =?UTF-8?q?ype=20[com.baomidou.mybatisplus.annotation.IdType]=20=20=20=20?= =?UTF-8?q?=20=E9=97=AE=E9=A2=98=E4=B8=80=EF=BC=9AIdTypeEnvironmentPostPro?= =?UTF-8?q?cessor.getIdType=20=E4=B8=AD=20environment.getProperty(ID=5FTYP?= =?UTF-8?q?E=5FKEY,=20IdType.class)=20=E8=8E=B7=E5=8F=96=E5=88=B0=E4=BA=86?= =?UTF-8?q?=E4=B8=8A=E4=B8=80=E6=AC=A1=E9=83=A8=E7=BD=B2=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E6=97=B6=E7=9A=84=20IdType=20=E5=AF=B9=E8=B1=A1=EF=BC=8C?= =?UTF-8?q?=E8=80=8C=E4=B8=8A=E4=B8=80=E6=AC=A1=E7=9A=84=20IdType=20?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=EF=BC=8C=E5=92=8C=E6=9C=AC=E6=AC=A1=E9=83=A8?= =?UTF-8?q?=E7=BD=B2=E6=97=B6=20IdType.class=20=E7=9A=84=E7=B1=BB=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E5=99=A8=E4=B8=8D=E4=B8=80=E8=87=B4=EF=BC=8C=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E6=8A=A5=E9=94=99=EF=BC=9B=20=20=20=20=20=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BA=8C=EF=BC=9Aorg.springframework.boot.context.pro?= =?UTF-8?q?perties.bind.BindConverter.convert=20=E4=B8=AD=EF=BC=8Cdelegate?= =?UTF-8?q?.canConvert=20=E8=BF=94=E5=9B=9E=E7=9A=84=E9=83=BD=E6=98=AFfals?= =?UTF-8?q?e=EF=BC=8C=E6=9C=80=E7=BB=88=EF=BC=9Athrow=20(failure=20!=3D=20?= =?UTF-8?q?null)=20=3F=20failure=20:=20new=20ConverterNotFoundException(so?= =?UTF-8?q?urceType,=20targetType);=20=20=20=20=20=E5=8E=9F=E5=9B=A0?= =?UTF-8?q?=E5=88=86=E6=9E=90=EF=BC=9A=20=20=20=20=20=E9=A6=96=E5=85=88=20?= =?UTF-8?q?ConfigurableEnvironment=20=20=20=20=20=20=20=20=20ConfigurableE?= =?UTF-8?q?nvironment.getProperty(...)=20=E7=9A=84=E6=9F=A5=E6=89=BE?= =?UTF-8?q?=E9=A1=BA=E5=BA=8F=E6=98=AF=E5=88=86=E5=B1=82=E6=AC=A1=E7=9A=84?= =?UTF-8?q?=EF=BC=9A=20=20=20=20=20=20=20=20=201=E3=80=81=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=E8=A1=8C=E5=8F=82=E6=95=B0=EF=BC=88CommandLinePropert?= =?UTF-8?q?ySource=EF=BC=8C=E5=8D=B3=20--key=3Dvalue=EF=BC=89=20=20=20=20?= =?UTF-8?q?=20=20=20=20=202=E3=80=81Java=20=E7=B3=BB=E7=BB=9F=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=EF=BC=88System.getProperties()=EF=BC=8C=E5=AF=B9?= =?UTF-8?q?=E5=BA=94=20SystemPropertiesPropertySource=EF=BC=89=20=20=20=20?= =?UTF-8?q?=20=20=20=20=203=E3=80=81=E6=93=8D=E4=BD=9C=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F=EF=BC=88System.getenv()?= =?UTF-8?q?=EF=BC=8C=E5=AF=B9=E5=BA=94=20SystemEnvironmentPropertySource?= =?UTF-8?q?=EF=BC=89=20=20=20=20=20=20=20=20=204=E3=80=81application.yml?= =?UTF-8?q?=20/=20application.properties=EF=BC=88OriginTrackedMapPropertyS?= =?UTF-8?q?ource=EF=BC=89=20=20=20=20=20=20=20=20=205=E3=80=81=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E5=B1=9E=E6=80=A7=EF=BC=88DefaultPropertiesPropertySo?= =?UTF-8?q?urce=EF=BC=89=20=20=20=20=20=E5=85=B6=E6=AC=A1=EF=BC=9ASpring?= =?UTF-8?q?=20=E7=9A=84=E5=B1=9E=E6=80=A7=E7=BB=91=E5=AE=9A=E7=94=A8?= =?UTF-8?q?=E5=88=B0=E4=BA=86=20ConfigurationPropertySource=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20ConfigurationPropertySource=EF=BC=9A=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20=20=20=E5=AE=83=E6=98=AF=20Spring=20Boot=202.?= =?UTF-8?q?x=20=E4=BB=A5=E5=90=8E=E5=BC=95=E5=85=A5=E7=9A=84=E6=8A=BD?= =?UTF-8?q?=E8=B1=A1=EF=BC=8C=E8=A1=A8=E7=A4=BA=E9=85=8D=E7=BD=AE=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E7=9A=84=E6=9D=A5=E6=BA=90=E3=80=82=20=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20=20=E6=AF=94=E5=A6=82=EF=BC=9A=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20=20=20.properties=20/=20.yml=20=E6=96=87?= =?UTF-8?q?=E4=BB=B6=EF=BC=8C=20=20=20=20=20=20=20=20=20=20=20=20=20?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E5=B1=9E=E6=80=A7=EF=BC=88System.getProperti?= =?UTF-8?q?es()=EF=BC=89=EF=BC=8C=20=20=20=20=20=20=20=20=20=20=20=20=20?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F=EF=BC=88System.getenv()?= =?UTF-8?q?=EF=BC=89=EF=BC=8C=20=20=20=20=20=20=20=20=20=20=20=20=20?= =?UTF-8?q?=E7=94=9A=E8=87=B3=20Nacos=E3=80=81Apollo=20=E8=BF=99=E6=A0=B7?= =?UTF-8?q?=E7=9A=84=E8=BF=9C=E7=A8=8B=E9=85=8D=E7=BD=AE=E4=B8=AD=E5=BF=83?= =?UTF-8?q?=E3=80=82=20=20=20=20=20=20=20=20=20=20=20=20=20=E5=AE=83?= =?UTF-8?q?=E7=BB=9F=E4=B8=80=E6=88=90=20ConfigurationPropertySource=20?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=EF=BC=8CSpring=20Boot=20=E5=B0=B1=E8=83=BD?= =?UTF-8?q?=E7=94=A8=E5=90=8C=E4=B8=80=E5=A5=97=E9=80=BB=E8=BE=91=E5=8E=BB?= =?UTF-8?q?=E8=AF=BB=E5=8F=96=E9=85=8D=E7=BD=AE=E3=80=82=20=20=20=20=20=20?= =?UTF-8?q?=20=20=20=E5=92=8C=20ConfigurableEnvironment=20=E7=9A=84?= =?UTF-8?q?=E5=85=B3=E7=B3=BB=20=20=20=20=20=20=20=20=20=20=20=20=20Config?= =?UTF-8?q?urableEnvironment=20=E5=86=85=E9=83=A8=E6=8C=81=E6=9C=89?= =?UTF-8?q?=E4=B8=80=E7=B3=BB=E5=88=97=20PropertySource=E3=80=82=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20=20=20=20=20Spring=20Boot=20=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E6=97=B6=E4=BC=9A=E6=8A=8A=E8=BF=99=E4=BA=9B=20Proper?= =?UTF-8?q?tySource=20=E9=80=82=E9=85=8D=E6=88=90=20ConfigurationPropertyS?= =?UTF-8?q?ource=EF=BC=8C=20=20=20=20=20=20=20=20=20=20=20=20=20=E8=BF=99?= =?UTF-8?q?=E6=A0=B7=E5=B1=9E=E6=80=A7=E7=BB=91=E5=AE=9A=E5=99=A8=EF=BC=88?= =?UTF-8?q?Binder=EF=BC=89=E5=B0=B1=E5=8F=AF=E4=BB=A5=E4=BB=8E=E4=B8=AD?= =?UTF-8?q?=E8=AF=BB=E5=8F=96=E9=85=8D=E7=BD=AE=E5=80=BC=E3=80=82=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20=20=20=20=20=E4=B9=9F=E5=B0=B1=E6=98=AF?= =?UTF-8?q?=E8=AF=B4=EF=BC=9A=20=20=20=20=20=20=20=20=20=20=20=20=20enviro?= =?UTF-8?q?nment.getProperty("my.key")=20=E8=AF=BB=E5=87=BA=E6=9D=A5?= =?UTF-8?q?=E7=9A=84=E5=80=BC=EF=BC=8C=20=20=20=20=20=20=20=20=20=20=20=20?= =?UTF-8?q?=20=E5=92=8C=20Binder=20=E9=87=8C=20ConfigurationPropertySource?= =?UTF-8?q?=20=E6=8F=90=E4=BE=9B=E7=9A=84=E5=80=BC=EF=BC=8C=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20=20=20=E6=9C=AC=E8=B4=A8=E4=B8=8A=E6=98=AF?= =?UTF-8?q?=E5=90=8C=E4=B8=80=E6=89=B9=E9=85=8D=E7=BD=AE=E6=BA=90=EF=BC=8C?= =?UTF-8?q?=E5=8F=AA=E6=98=AF=E8=B5=B0=E7=9A=84=20API=20=E4=B8=8D=E4=B8=80?= =?UTF-8?q?=E6=A0=B7=E3=80=82=20=20=20=20=20=20=20=20=20=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=9Aorg.springframework.boot.co?= =?UTF-8?q?ntext.properties.bind.BindConverter.convert=20=E7=9A=84?= =?UTF-8?q?=E5=8F=82=E6=95=B0=EF=BC=9AObject=20source,=20TypeDescriptor=20?= =?UTF-8?q?sourceType,=20TypeDescriptor=20targetType=20=20=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20source=20=E6=98=AF=E4=B8=8A=E4=B8=80=E6=AC=A1?= =?UTF-8?q?=E9=83=A8=E7=BD=B2=E6=97=B6=E7=9A=84=20IdType=20=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=20=20=20=20=20=20=20=20=20=20=20=20=20sourceType=20?= =?UTF-8?q?=E7=9A=84=E7=B1=BB=E5=8A=A0=E8=BD=BD=E5=99=A8=20=EF=BC=88source?= =?UTF-8?q?Type.getType().getClassLoader()=EF=BC=89=20=E4=B8=8E=20targetTy?= =?UTF-8?q?pe=20=E7=9A=84=E7=B1=BB=E5=8A=A0=E8=BD=BD=E5=99=A8=20=EF=BC=88t?= =?UTF-8?q?argetType.getType().getClassLoader()=EF=BC=89=E4=B8=8D=E4=B8=80?= =?UTF-8?q?=E8=87=B4=EF=BC=8C=E6=8A=9B=E5=87=BA=EF=BC=9AConverterNotFoundE?= =?UTF-8?q?xception?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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); } --- .../IdTypeEnvironmentPostProcessor.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/config/IdTypeEnvironmentPostProcessor.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/config/IdTypeEnvironmentPostProcessor.java index 3a67b905f..bb79410da 100644 --- a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/config/IdTypeEnvironmentPostProcessor.java +++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/config/IdTypeEnvironmentPostProcessor.java @@ -9,7 +9,10 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.boot.SpringApplication; import org.springframework.boot.env.EnvironmentPostProcessor; import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.MapPropertySource; +import java.util.HashMap; +import java.util.Map; import java.util.Set; /** @@ -56,11 +59,23 @@ public class IdTypeEnvironmentPostProcessor implements EnvironmentPostProcessor } public IdType getIdType(ConfigurableEnvironment environment) { - return environment.getProperty(ID_TYPE_KEY, IdType.class); + // return environment.getProperty(ID_TYPE_KEY, IdType.class); + String value = environment.getProperty(ID_TYPE_KEY); + try { + return StrUtil.isNotBlank(value) ? IdType.valueOf(value) : IdType.NONE; + } catch (IllegalArgumentException ex) { + log.error("无法解析 id-type 配置值:{}", value, ex); + return IdType.NONE; + } + } public void setIdType(ConfigurableEnvironment environment, IdType idType) { - environment.getSystemProperties().put(ID_TYPE_KEY, idType); + // environment.getSystemProperties().put(ID_TYPE_KEY, idType); + // log.info("[setIdType][修改 MyBatis Plus 的 idType 为({})]", idType); + Map map = new HashMap<>(); + map.put(ID_TYPE_KEY, idType); + environment.getPropertySources().addFirst(new MapPropertySource("mybatisPlusIdType", map)); log.info("[setIdType][修改 MyBatis Plus 的 idType 为({})]", idType); }