Skip to content

Commit

Permalink
fix: 修复使用端点重启系统时出现 java.lang.LinkageError: loader 'app' attempted dup…
Browse files Browse the repository at this point in the history
…licate class definition for 问题
  • Loading branch information
houkunlin committed Aug 3, 2024
1 parent 09d8087 commit d151187
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
// 只使用字典值转换
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit d151187

Please sign in to comment.