【问题标题】:ClassNotFoundException after upgrading from Spring 3.0.5 to 3.2.1 in RCP application在 RCP 应用程序中从 Spring 3.0.5 升级到 3.2.1 后出现 ClassNotFoundException
【发布时间】:2014-03-02 08:48:16
【问题描述】:

我有一个包含数百个捆绑包的 RCP 应用程序,它与 Spring dm 连接。升级到 Spring 3.2.1 后,我现在在几个捆绑包中得到以下异常。起初我认为这可能是由 dm 中的一些魔法引起的,但在通过初始化不带 dm 的包(只需以编程方式启动 ApplicationContext)来测试该理论之后,我仍然面临同样的异常。

堆栈跟踪:

Exception in thread "SpringOsgiExtenderThread-130" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'FileSystemsStackViewControlFactory' defined in OSGi resource[classpath:spring/filesystem-ui.xml|bnd.id=176|bnd.sym=filesystem.ui]: Instantiation of bean failed; nested exception is org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1011)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:957)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:490)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
    at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:69)
    at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:355)
    at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
    at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:320)
    at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:132)
    at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
    at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:237)
    at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
    at org.springframework.cglib.proxy.Enhancer.create(Enhancer.java:285)
    at org.springframework.beans.factory.support.CglibSubclassingInstantiationStrategy$CglibSubclassCreator.instantiate(CglibSubclassingInstantiationStrategy.java:117)
    at org.springframework.beans.factory.support.CglibSubclassingInstantiationStrategy.instantiateWithMethodInjection(CglibSubclassingInstantiationStrategy.java:69)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:91)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1004)
    ... 15 more
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.GeneratedMethodAccessor58.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:384)
    at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:219)
    ... 21 more
Caused by: java.lang.NoClassDefFoundError: org/springframework/cglib/proxy/Factory
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    ... 26 more
Caused by: java.lang.ClassNotFoundException: org.springframework.cglib.proxy.Factory
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:501)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 29 more

原始清单是 Require-Bundle 和 Package-Import 的混合体,所以我尝试完全删除 Require-Bundle。没想到这会改变任何事情,但危急时刻需要采取危急措施,我是对的,仍然一无所获。

万不得已,我也试过加这个属性,还是没变。

DynamicImport-Package: *

我知道 Spring 在 3.1 版左右改变了他们对 cglib 的使用,将 cglib 和 asm 嵌入到他们的核心 jar 中,但我已经包含了所有 cglib 和 asm 包的导入,但无济于事。

清单:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: File System UI
Bundle-SymbolicName: com.mycorp.filesystem.ui;singleton:=true
Bundle-Version: 15.7.0.qualifier
Bundle-Activator: com.mycorp.filesystem.ui.internal.Activator
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Import-Package: com.mycorpcse.utils.eclipse,
 com.mycorp.common.ui,
      :
   Many other in house dependencies
      :
 com.mycorp.core,
 org.eclipse.core.commands,
      :
   Many other eclipse dependencies
      :
 org.eclipse.ui.views.properties,
 org.osgi.framework;version="1.7.0",
 org.springframework.asm;version="3.2.1.RELEASE",
 org.springframework.asm.commons;version="3.2.1.RELEASE",
 org.springframework.asm.signature;version="3.2.1.RELEASE",
 org.springframework.asm.util;version="3.2.1.RELEASE",
 org.springframework.beans;version="3.0.5.RELEASE",
 org.springframework.beans.factory.annotation,
 org.springframework.cglib;version="3.2.1.RELEASE",
 org.springframework.cglib.beans;version="3.2.1.RELEASE",
 org.springframework.cglib.core;version="3.2.1.RELEASE",
 org.springframework.cglib.proxy;version="3.2.1.RELEASE",
 org.springframework.cglib.reflect;version="3.2.1.RELEASE",
 org.springframework.cglib.transform;version="3.2.1.RELEASE",
 org.springframework.cglib.transform.impl;version="3.2.1.RELEASE",
 org.springframework.cglib.util;version="3.2.1.RELEASE"
 Export-Package: com.mycorp.filesystem.ui,
 com.mycorp.filesystem.ui.columns,
 com.mycorp.filesystem.ui.model

更新:我现在意识到只有在使用lookup method injection 时才会出现这种特殊情况。由于我仍然不知道如何修复它,我不得不更改配置以不使用此功能。

【问题讨论】:

  • 您似乎错过了一个仍指向 3.0.5 而不是 3.2.1 的依赖 spring-beans,并确保您必须使用适当的 Spring 核心 jar。从 bean 错误和堆栈跟踪来看,您使用的实际包/jar 不是您认为正在使用的。
  • 我的目标平台只部署了 3.2.1。 3.0.5 只是未更新的最低版本,但这并不重要,因为 3.2.1 部署仍将满足依赖关系。
  • 我会说 spring-core jar 不是您部署的一部分,至少不是包含重新打包的 cglib/asm 内容的那个。
  • 它在那里,因为 bundle 解析了,但是 Spring 初始化失败。

标签: spring eclipse-plugin osgi eclipse-rcp spring-dm


【解决方案1】:

我们通过将 org.springframework.cglib 等的 import-package 添加到 org.springframework.transaction 包中解决了类似的问题。

【讨论】:

    【解决方案2】:

    似乎在 Spring 3.2 中他们改变了内部类结构。使用默认的 OSGI 包无法找到这些 clib 类。因此,您必须在 MANIFEST.MF 中明确指定您需要在上下文中加载这些包。

    您可以在 jar 文件中编辑 MANIFEST.MF 文件。在 Import-Package 部分添加以下 3 个包:

    'org.springframework.cglib.core','org.springframework.cglib.proxy','org.springframework.beans.factory'

    或者,如果您使用 gradle,您可以执行以下操作(假设您已经启用了 osgi 插件)

    jar { manifest { instruction 'Import-Package', 'org.springframework.cglib.core', 'org.springframework.cglib.proxy', 'org.springframework.beans.factory', '*' } }

    【讨论】:

      猜你喜欢
      • 2012-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-14
      • 2019-05-04
      • 1970-01-01
      • 2014-02-21
      相关资源
      最近更新 更多