如何解决java.lang.linkageerror:加载程序约束冲突

sqougxex  于 2021-07-08  发布在  Java
关注(0)|答案(1)|浏览(574)

每当我在eclipse中部署liferayportlet的war文件时,我都会遇到以下错误。有人能帮我知道为什么会发生这种情况以及如何解决它吗。

java.lang.LinkageError: loader constraint violation: when resolving overridden method "com.liferay.portal.spring.extender.internal.context.ModuleBeanFactoryPostProcessor.postProcessBeanFactory(Lorg/springframework/beans/factory/config/ConfigurableListableBeanFactory;)V" the class loader (instance of org/eclipse/osgi/internal/loader/EquinoxClassLoader) of the current class, com/liferay/portal/spring/extender/internal/context/ModuleBeanFactoryPostProcessor, and its superclass loader (instance of org/apache/catalina/loader/WebappClassLoader), have different Class objects for the type org/springframework/beans/factory/config/ConfigurableListableBeanFactory used in the signature
    at com.liferay.portal.spring.extender.internal.context.ModuleApplicationContextRegistrator._createApplicationContext(ModuleApplicationContextRegistrator.java:138)
    at com.liferay.portal.spring.extender.internal.context.ModuleApplicationContextRegistrator.start(ModuleApplicationContextRegistrator.java:60)
    at sun.reflect.GeneratedMethodAccessor756.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.felix.dm.InvocationUtil.invokeMethod(InvocationUtil.java:111)
    at org.apache.felix.dm.InvocationUtil.invokeCallbackMethod(InvocationUtil.java:66)
    at org.apache.felix.dm.impl.ComponentImpl.invokeCallbackMethod(ComponentImpl.java:769)
    at org.apache.felix.dm.impl.ComponentImpl.invoke(ComponentImpl.java:760)
    at org.apache.felix.dm.impl.ComponentImpl.bindService(ComponentImpl.java:705)
    at org.apache.felix.dm.impl.ComponentImpl.access$400(ComponentImpl.java:54)
    at org.apache.felix.dm.impl.ComponentImpl$7.run(ComponentImpl.java:202)
    at org.apache.felix.dm.impl.SerialExecutor.runTask(SerialExecutor.java:137)
    at org.apache.felix.dm.impl.SerialExecutor.runTasks(SerialExecutor.java:119)
    at org.apache.felix.dm.impl.SerialExecutor.execute(SerialExecutor.java:85)
    at org.apache.felix.dm.impl.ComponentImpl.calculateStateChanges(ComponentImpl.java:252)
    at org.apache.felix.dm.impl.ComponentImpl.start(ComponentImpl.java:440)
    at org.apache.felix.dm.DependencyManager.add(DependencyManager.java:167)
    at com.liferay.portal.spring.extender.internal.context.ModuleApplicationContextExtender$ModuleApplicationContextExtension.start(ModuleApplicationContextExtender.java:228)
    at org.apache.felix.utils.extender.AbstractExtender.createExtension(AbstractExtender.java:259)
    at org.apache.felix.utils.extender.AbstractExtender.modifiedBundle(AbstractExtender.java:232)
    at org.apache.felix.utils.extender.AbstractExtender.addingBundle(AbstractExtender.java:192)
    at org.osgi.util.tracker.BundleTracker$Tracked.customizerAdding(BundleTracker.java:469)
    at org.osgi.util.tracker.BundleTracker$Tracked.customizerAdding(BundleTracker.java:1)
    at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)
    at org.osgi.util.tracker.AbstractTracked.trackInitial(AbstractTracked.java:183)
    at org.osgi.util.tracker.BundleTracker.open(BundleTracker.java:156)
    at org.apache.felix.utils.extender.AbstractExtender.startTracking(AbstractExtender.java:150)
    at org.apache.felix.utils.extender.AbstractExtender.doStart(AbstractExtender.java:142)
    at org.apache.felix.utils.extender.AbstractExtender.start(AbstractExtender.java:114)
    at com.liferay.portal.spring.extender.internal.context.ModuleApplicationContextExtender.activate(ModuleApplicationContextExtender.java:71)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.felix.scr.impl.inject.BaseMethod.invokeMethod(BaseMethod.java:224)
    at org.apache.felix.scr.impl.inject.BaseMethod.access$500(BaseMethod.java:39)
    at org.apache.felix.scr.impl.inject.BaseMethod$Resolved.invoke(BaseMethod.java:617)
    at org.apache.felix.scr.impl.inject.BaseMethod.invoke(BaseMethod.java:501)
    at org.apache.felix.scr.impl.inject.ActivateMethod.invoke(ActivateMethod.java:302)
    at org.apache.felix.scr.impl.inject.ActivateMethod.invoke(ActivateMethod.java:294)
    at org.apache.felix.scr.impl.manager.SingleComponentManager.createImplementationObject(SingleComponentManager.java:297)
    at org.apache.felix.scr.impl.manager.SingleComponentManager.createComponent(SingleComponentManager.java:108)
    at org.apache.felix.scr.impl.manager.SingleComponentManager.getService(SingleComponentManager.java:906)
    at org.apache.felix.scr.impl.manager.SingleComponentManager.getServiceInternal(SingleComponentManager.java:879)
    at org.apache.felix.scr.impl.manager.AbstractComponentManager.activateInternal(AbstractComponentManager.java:748)
    at org.apache.felix.scr.impl.manager.AbstractComponentManager.enableInternal(AbstractComponentManager.java:674)
    at org.apache.felix.scr.impl.manager.AbstractComponentManager.enable(AbstractComponentManager.java:429)
    at org.apache.felix.scr.impl.manager.ConfigurableComponentHolder.enableComponents(ConfigurableComponentHolder.java:657)
    at org.apache.felix.scr.impl.BundleComponentActivator.initialEnable(BundleComponentActivator.java:341)
    at org.apache.felix.scr.impl.Activator.loadComponents(Activator.java:403)
    at org.apache.felix.scr.impl.Activator.access$200(Activator.java:54)
    at org.apache.felix.scr.impl.Activator$ScrExtension.start(Activator.java:278)
    at org.apache.felix.utils.extender.AbstractExtender.createExtension(AbstractExtender.java:259)
    at org.apache.felix.utils.extender.AbstractExtender.modifiedBundle(AbstractExtender.java:232)
    at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:482)
    at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:1)
    at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:232)
    at org.osgi.util.tracker.BundleTracker$Tracked.bundleChanged(BundleTracker.java:444)
    at org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:905)
    at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
    at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
    at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEventPrivileged(EquinoxEventPublisher.java:165)
    at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:75)
    at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:67)
    at org.eclipse.osgi.internal.framework.EquinoxContainerAdaptor.publishModuleEvent(EquinoxContainerAdaptor.java:102)
    at org.eclipse.osgi.container.Module.publishEvent(Module.java:461)
    at org.eclipse.osgi.container.Module.start(Module.java:452)
    at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:402)
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1258)
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1230)
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:512)
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:361)
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:312)
osh3o9ms

osh3o9ms1#

java.lang.linkageerror发生在使用依赖版本(如v1)编译代码,然后使用依赖版本(如v2)运行代码时。
示例说明:编译时使用的是v1的父类(假设它来自liferay)

class Parent {
    public void method(String s) {
        s = "Hello " + s;
        System.out.println(s);
    }
}

// this is your project class
class Child extends Parent {
    @Overridden
    public void method(String s) {
        super.method(s);
        System.out.println("Hello from child : " + s);
    } 
}

因此,在构建项目jar时可以很好地进行编译。
但是,在运行时,您使用的是版本v2的父类,其方法定义如下 public void method(String s, int i) . 因此,它无法将您的类链接到父类,因此出现错误。
这里是包含类的库的运行时版本和编译时版本 com.liferay.portal.spring.extender.internal.context.ModuleBeanFactoryPostProcessor 它们是不同的。保持两个版本与编译时相同,一切都会很好。

相关问题