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);