问题描述
我在/target/class/..... 中通过 wsimport 为 WS 服务生成存根并使用 devtools 运行 Spring Boot 应用程序时遇到异常.
I obtained an exception when generated a stub for a WS service by wsimport in /target/class/..... and run a spring boot application with devtools.
Caused by: java.lang.IllegalArgumentException: com....从方法引用的服务在类加载器中不可见
我发现 spring devtools 类加载器存在问题,RestartClassLoader,因为对类的两个不同引用(RestartClassLoader 和 AppClassLoader)
I found that an issue with spring devtools class loader, RestartClassLoader, because of two different references to a Class (RestartClassLoader and AppClassLoader)
private static void ensureVisible(ClassLoader ld, Class<?> c) {
Class<?> type = null;
try {
type = Class.forName(c.getName(), false, ld);
} catch (ClassNotFoundException e) {
if (type != c) {
throw new IllegalArgumentException(c.getName() +
" referenced from a method is not visible from class loader");
}
}
}
我试图在 spring-devtools.properties 中添加对 jar 文件的引用以重新启动.include=/.....jar
I was trying to add a reference to a jar file in spring-devtools.properties to restart.include=/.....jar
Spring Boot 2.0.0.RELEASE Java 9
推荐答案
由于它们是生成的类,因此您必须将它们从 Spring Devtools重新启动"类加载器中排除.
Since they are generated classes you have to exclude them from Spring Devtools "restart" classloader.
- 创建一个
/src/main/resources/META-INF/spring-devtools.properties
文件 添加诸如
restart.exclude.*
之类的属性以从重启类加载器中排除类(例如,您可以使用restart.exclude.mygeneratedclasses=/*[generated]*.class
排除所有带有generated
词作为包或类名的一部分的类)
- Create a
/src/main/resources/META-INF/spring-devtools.properties
file Add properties like
restart.exclude.*
to exclude classes from restart classloader (example, you can userestart.exclude.mygeneratedclasses=/*[generated]*.class
to exclude all classes withgenerated
word as part of package or class name)
完成.现在,您可以使用 devtools,并且 WS 生成的类没有问题.
Done. Now you can use devtools and have no issues with WS generated classes.
参考:
[1] https://github.com/spring-projects/spring-boot/issues/4529
这篇关于从方法引用的 java.lang.IllegalArgumentException 在类加载器中不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!