0

I have an RCP application with several hundred bundles that is wired with Spring dm. After upgrading to Spring 3.2.1, I now get the following exception in a couple of bundles. At first I thought it may be caused by some magic in dm, but after testing that theory by initializing the bundle without dm (simply starting up an ApplicationContext programatically), I still faced the same exception.

Stacktrace:

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

The original manifest was a mixture of Require-Bundle and Package-Import, so I tried removing the Require-Bundle altogether. Didn't expect this to change anything, but desperate times call for desperate measures, and I was right, still nothing.

As a last resort, I also tried adding this attribute, still no change.

DynamicImport-Package: *

I know that Spring changed their usage of cglib around version 3.1 to embed cglib and asm within their core jars, but I have included imports for all the cglib and asm packages to no avail.

Manifest:

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

Update: I now realize that this particular case is caused only when using lookup method injection. As I still don't know how to fix it, I have had to alter the config to not use this feature.

Robin
  • 24,062
  • 5
  • 49
  • 58
  • You appear to have missed a dependendy spring-beans which still points to 3.0.5 and not 3.2.1 and make sure that you have to appropriate Spring core jar. Judging from the beans error and stacktrace the actual bundles/jars you are using are not the ones you think you are using. – M. Deinum Feb 06 '14 at 07:16
  • Only 3.2.1 is deployed in my target platform. The 3.0.5 is simply the minimum version as that wasn't updated, but that doesn't matter as the 3.2.1 deployment will still satisfy the dependency. – Robin Feb 06 '14 at 14:35
  • I would say then that the spring-core jar isn't part of your deployment, at least not the one that contains the repacked cglib/asm stuff. – M. Deinum Feb 07 '14 at 08:00
  • It is there, as the bundle resolves, but the Spring initialization fails. – Robin Feb 07 '14 at 18:29

2 Answers2

0

We solved a similar problem by adding import-package of org.springframework.cglib etc. to the org.springframework.transaction bundle.

0

It seems in Spring 3.2 they changed the internal class structure. With the default OSGI package those clib classes can not be found. Therefore you have to explicit specify in the MANIFEST.MF that you need those packages loaded in the context.

You can edit the MANIFEST.MF file in your jar file. In Import-Package section add the following 3 packages:

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

Or if you are using gradle you can do the following (assuming you have osgi plugin enabled already)

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

Y.Y
  • 531
  • 4
  • 9