`mvn spring-boot:run` 导致了 `java.lang.LinkageError: loader constraint violation` 错误。

huangapple go评论96阅读模式
英文:

mvn spring-boot:run results in java.lang.LinkageError: loader constraint violation

问题

我有一个项目,将其作为可执行的JAR运行时正常运行。
然而,当我使用 mvn spring-boot:run 时,我遇到以下错误:

在线程 "Thread-129" 中的异常 java.lang.LinkageError: loader constraint violation: loader (instance of sun/misc/Launcher$AppClassLoader) previously initiated loading for a different type with name "org/test/DefaultIdAndText"
	at java.lang.ClassLoader.defineClass1(Native Method)
	...

我无法分享代码,因为它是私有的。
我确实有相同的库JAR依赖项两次(直接1次),并且还有1次通过另一个依赖项。
我尝试过添加排除项,但似乎没有任何作用。

奇怪的是,当我直接运行JAR时,应用程序运行正常。

更新

我还注意到了以下情况... 我认为这就是问题所在:

TomcatEmbeddedWebappClassLoader
  context: ROOT
  delegate: true
-----------> Parent Classloader:
org.springframework.boot.devtools.restart.classloader.RestartClassLoader@79fe98a7

我将尝试禁用开发工具的类加载器和重新加载。

英文:

I have a project that runs fine with I run it as an executable JAR.
However, when I use mvn spring-boot:run I get the following error:

 exception in thread "Thread-129" java.lang.LinkageError: loader constraint violation: loader (instance of sun/misc/Launcher$AppClassLoader) previously initiated loading for a different type with name "org/test/DefaultIdAndText"
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at java.lang.Class.getDeclaredFields0(Native Method)
	at java.lang.Class.privateGetDeclaredFields(Class.java:2583)
	at java.lang.Class.getDeclaredFields(Class.java:1916)
	at com.fasterxml.jackson.databind.util.ClassUtil.getDeclaredFields(ClassUtil.java:1055)
	at com.fasterxml.jackson.databind.introspect.AnnotatedFieldCollector._findFields(AnnotatedFieldCollector.java:66)
	at com.fasterxml.jackson.databind.introspect.AnnotatedFieldCollector.collect(AnnotatedFieldCollector.java:41)
	at com.fasterxml.jackson.databind.introspect.AnnotatedFieldCollector.collectFields(AnnotatedFieldCollector.java:36)
	at com.fasterxml.jackson.databind.introspect.AnnotatedClass._fields(AnnotatedClass.java:349)
	at com.fasterxml.jackson.databind.introspect.AnnotatedClass.fields(AnnotatedClass.java:321)
	at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector._addFields(POJOPropertiesCollector.java:379)
	at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.collectAll(POJOPropertiesCollector.java:308)
	at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.getJsonValueAccessor(POJOPropertiesCollector.java:196)
	at com.fasterxml.jackson.databind.introspect.BasicBeanDescription.findJsonValueAccessor(BasicBeanDescription.java:251)
	at com.fasterxml.jackson.databind.ser.BasicSerializerFactory.findSerializerByAnnotations(BasicSerializerFactory.java:346)
	at com.fasterxml.jackson.databind.ser.BeanSerializerFactory._createSerializer2(BeanSerializerFactory.java:216)
	at com.fasterxml.jackson.databind.ser.BeanSerializerFactory.createSerializer(BeanSerializerFactory.java:165)
	at com.fasterxml.jackson.databind.SerializerProvider._createUntypedSerializer(SerializerProvider.java:1389)
	at com.fasterxml.jackson.databind.SerializerProvider._createAndCacheUntypedSerializer(SerializerProvider.java:1336)
	at com.fasterxml.jackson.databind.SerializerProvider.findValueSerializer(SerializerProvider.java:510)
	at com.fasterxml.jackson.databind.SerializerProvider.findTypedValueSerializer(SerializerProvider.java:713)
	at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:308)
	at com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:3905)
	at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:3219)
	at lambda$commit$0(EventStoreService.java:120)
	at java.util.concurrent.ConcurrentHashMap$EntrySpliterator.forEachRemaining(ConcurrentHashMap.java:3606)
	at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)

I can't share the code because it is proprietary.
I do have the same library jar dependency two times (1 directly), and 1 through another dependency.
I added an exclusion but this doesn't seem to do anything.

The strange thing is that the application runs fine, when I run the jar directly.

Update

I also noticed the following... and I think it is the problem:

TomcatEmbeddedWebappClassLoader
  context: ROOT
  delegate: true
----------> Parent Classloader:
org.springframework.boot.devtools.restart.classloader.RestartClassLoader@79fe98a7

I will try to disable the devtools classloader and reloading.

答案1

得分: 1

问题出在 Spring 开发工具上。
我不得不将它移除,并且还要从任何其他依赖项中排除掉它。

我首先通过运行以下命令并查看其位置来将其移除:

dependency:tree -Dverbose

然后,我要么将依赖项注释掉,要么添加以下排除项:

<exclusion>
    <!-- 在此处声明排除项 -->
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
</exclusion>

移除后,错误消失了,现在我看到:

TomcatEmbeddedWebappClassLoader
  context: ROOT
  delegate: true
----------> Parent Classloader:
java.net.URLClassLoader@44052821
英文:

The problem was spring dev tools.
I had to remove it, and also remove it with an exclusion from any other dependencies.

I removed it by first running the following and seeing where it was located:

dependency:tree -Dverbose

And following I either commented out the dependency or added the following exclusion:

&lt;exclusion&gt;  &lt;!-- declare the exclusion here --&gt;
					&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
					&lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
				&lt;/exclusion&gt;

After removing it, the error went away and I now see:

TomcatEmbeddedWebappClassLoader
  context: ROOT
  delegate: true
----------&gt; Parent Classloader:
java.net.URLClassLoader@44052821

huangapple
  • 本文由 发表于 2020年5月3日 23:20:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/61576871.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定