From d151187820265f7631329f9264a47df657bdf372 Mon Sep 17 00:00:00 2001 From: HouKunLin Date: Sat, 3 Aug 2024 15:57:04 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E7=AB=AF=E7=82=B9=E9=87=8D=E5=90=AF=E7=B3=BB=E7=BB=9F=E6=97=B6?= =?UTF-8?q?=E5=87=BA=E7=8E=B0=20java.lang.LinkageError:=20loader=20'app'?= =?UTF-8?q?=20attempted=20duplicate=20class=20definition=20for=20=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dict/starter/bytecode/IDictConverterGenerate.java | 4 ++-- .../starter/bytecode/IDictConverterGenerateAsmImpl.java | 7 +++++++ .../bytecode/IDictConverterGenerateJavassistImpl.java | 8 +++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/houkunlin/system/dict/starter/bytecode/IDictConverterGenerate.java b/src/main/java/com/houkunlin/system/dict/starter/bytecode/IDictConverterGenerate.java index e17788b..9b650e5 100644 --- a/src/main/java/com/houkunlin/system/dict/starter/bytecode/IDictConverterGenerate.java +++ b/src/main/java/com/houkunlin/system/dict/starter/bytecode/IDictConverterGenerate.java @@ -39,8 +39,8 @@ default void registerBean(final DefaultListableBeanFactory factory, final Class< final Constructor[] constructors = converterClass.getConstructors(); factory.registerSingleton(beanName, constructors[0].newInstance()); } - } catch (Exception e) { - logger.error("自动创建系统字典枚举 " + dictEnumClass.getName() + " 的 Converter 转换器失败,不影响系统启动,但是会影响此枚举转换器功能", e); + } catch (Throwable e) { + logger.error("自动创建系统字典枚举 {} 的 Converter 转换器失败,不影响系统启动,但是会影响此枚举转换器功能", dictEnumClass.getName(), e); } } diff --git a/src/main/java/com/houkunlin/system/dict/starter/bytecode/IDictConverterGenerateAsmImpl.java b/src/main/java/com/houkunlin/system/dict/starter/bytecode/IDictConverterGenerateAsmImpl.java index f3ff733..71c68e3 100644 --- a/src/main/java/com/houkunlin/system/dict/starter/bytecode/IDictConverterGenerateAsmImpl.java +++ b/src/main/java/com/houkunlin/system/dict/starter/bytecode/IDictConverterGenerateAsmImpl.java @@ -57,6 +57,13 @@ public Class getConverterClass(final Class dictEnumClass, final DictConver // 系统字典枚举类完全限定名 final String dictEnumClassName = dictEnumClass.getName().replace(".", "/"); final String converterClassName = dictEnumClassName + "SystemDictSpringConverter"; + + try { + // 尝试直接从已有的数据中加载 + return Class.forName(converterClassName); + } catch (Throwable ignore) { + } + final byte[] bytecode; if (dictConverter.onlyDictValue()) { // 只使用字典值转换 diff --git a/src/main/java/com/houkunlin/system/dict/starter/bytecode/IDictConverterGenerateJavassistImpl.java b/src/main/java/com/houkunlin/system/dict/starter/bytecode/IDictConverterGenerateJavassistImpl.java index 254ebd4..4e566fe 100644 --- a/src/main/java/com/houkunlin/system/dict/starter/bytecode/IDictConverterGenerateJavassistImpl.java +++ b/src/main/java/com/houkunlin/system/dict/starter/bytecode/IDictConverterGenerateJavassistImpl.java @@ -58,6 +58,12 @@ public Class getConverterClass(final Class dictEnumClass, final DictConver final String converterClassName = dictEnumClassName + "SystemDictSpringConverter"; final String dictEnumClassNameDescriptor = "L" + dictEnumClassName.replace(".", "/") + ";"; + try { + // 尝试直接从已有的数据中加载 + return Class.forName(converterClassName); + } catch (Throwable ignore) { + } + // 创建一个基础的对象信息 try { final CtClass ctClass = pool.getCtClass(converterClassName); @@ -71,7 +77,7 @@ public Class getConverterClass(final Class dictEnumClass, final DictConver return toClass(ctClass, dictEnumClass); } catch (NotFoundException e) { if (log.isDebugEnabled()) { - log.debug("首次创建 {} 转换器对象", converterClassName); + log.debug("首次创建 {} 转换器对象", converterClassName, e); } } final CtClass makeClass = pool.makeClass(converterClassName);