英文:
How to resolve java.lang.LinkageError: loader constraint violation
问题
我在Eclipse中部署Liferay portlet的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)
// 更多错误信息...
请问如何解决这个问题?
英文:
I am getting the below error whenever i am deploying war file of Liferay portlet in Eclipse.Can anyone help me to know why is it occurring and how to resolve it.
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)
答案1
得分: 6
java.lang.LinkageError
会在使用依赖版本v1编译代码,然后在依赖版本v2上运行代码时发生。
编译时,您正在使用v1版本的此Parent类(假设它来自Liferay)
class Parent {
public void method(String s) {
s = "Hello " + s;
System.out.println(s);
}
}
// 这是您的项目类
class Child extends Parent {
@Override
public void method(String s) {
super.method(s);
System.out.println("Hello from child: " + s);
}
}
因此,在构建项目jar时编译正常。
然而,在运行时,您正在使用具有public void method(String s, int i)
方法定义的版本v2的Parent类。因此,无法将您的类链接到该父类,从而导致错误。
在您的情况下,包含类com.liferay.portal.spring.extender.internal.context.ModuleBeanFactoryPostProcessor
的库的运行时版本和编译时版本不同。将两个版本保持与编译时相同,问题就会解决。
英文:
java.lang.LinkageError happens when code is compiled with dependency version say v1 and then is running with dependency version say v2.
Explanation sample:
While compiling you are using this Parent class of v1 (assume that's coming from 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);
}
}
So it is compiling fine while building the project jar.
However at the runtime you are using a Parent class of version v2 who has got the method definition like public void method(String s, int i)
. Hence that's not able to link your class to that parent class and so the error.
Here in your case, the runtime version and compile time version of the library containing class com.liferay.portal.spring.extender.internal.context.ModuleBeanFactoryPostProcessor
are different. Keep both versions same as your compile time and it will be all good.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论