ClassFormatError:EnhancerBySpringCGLIB中的重复方法名称和签名

时间:2016-09-23 23:03:57

标签: java spring cglib classformaterror

我真的很难过。我已将Spring库从4.0.6升级到4.3.2。使用4.3.2运行时,我们的一个测试失败。这是有问题的代码:

@Bean(name = SCHEDULER_FACTORY)
public SchedulerFactoryBean getSchedulerFactory()
{
    SchedulerFactoryBean schedulerFactory = new SchedulerFactoryBean();
    schedulerFactory.setConfigLocation(schedulerConfig);
    schedulerFactory.setResourceLoader(null);
    schedulerFactory.setDataSource(dataSource);
    schedulerFactory.setJobFactory(getSchedulerJobFactory());
    schedulerFactory.setAutoStartup(false);

    return schedulerFactory;
}

@Bean(name = SCHEDULER)
public Scheduler getScheduler()
{
    return getSchedulerFactory().getScheduler();
}

我收到错误java.lang.ClassFormatError: Duplicate method name&signature in class file org/springframework/scheduling/quartz/SchedulerFactoryBean$$EnhancerBySpringCGLIB$$bee87fe8$$EnhancerBySpringCGLIB$$6bb26669

使用spring 4.0.6框架运行测试完全正常,但是使用4.3.2,它失败了。使用4.0.6时,我使用的是cglib无依赖库。对于4.3.2,无论我是否使用cglib,测试都会失败。

Spring将cglib和objensis嵌入到4.3。*核心库中。 "此外,Spring Framework 4.3在spring-core.jar中嵌入了更新的ASM 5.1,CGLIB 3.2.4和Objenesis 2.4。" SpringDocs

我们在Spring框架4.0.6中使用了Java 8和cglib-no-dep 2.2。我们尝试使用和不使用独立库运行此代码,并看到相同的结果。

堆栈追踪:

  Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.quartz.Scheduler]: Factory method 'getScheduler' threw exception; nested exception is org.springframework.cglib.core.CodeGenerationException:java.lang.reflect.InvocationTargetException  >null
           at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
           at org.springframework.beans.factory.support.ConstructorResolver$3.run(ConstructorResolver.java:582)
           at java.security.AccessController.doPrivileged(Native Method)
           at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:579)
           ... 112 more
  Caused by: org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException  >null
           at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:345)
           at org.springframework.cglib.proxy.Enhancer.generate(Enhancer.java:492)
           at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:93)
  Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 188.486 sec
           at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:91)
           at org.springframework.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54)
           at java.util.concurrent.FutureTask.run(FutureTask.java:266)
           at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61)
           at org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34)
           at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:116)
           at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:291)
           at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:480)
           at org.springframework.cglib.proxy.Enhancer.createClass(Enhancer.java:337)
           at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.enhanceFactoryBean(ConfigurationClassEnhancer.java:452)
           at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:338)
           at com.example.SpringConfiguration$$EnhancerBySpringCGLIB$$54d3cb35.getSchedulerFactory(<generated>)
           at com.example.SpringConfiguration.getScheduler(SpringConfiguration.java:242)
           at com.example.SpringConfiguration$$EnhancerBySpringCGLIB$$54d3cb35.CGLIB$getScheduler$24(<generated>)
           at com.example.SpringConfiguration$$EnhancerBySpringCGLIB$$54d3cb35$$FastClassBySpringCGLIB$$a2a6e004.invoke(<generated>)
           at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
           at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356)
           at com.example.SpringConfiguration$$EnhancerBySpringCGLIB$$54d3cb35.getScheduler(<generated>)
           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.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
           ... 115 more
  Caused by: java.lang.reflect.InvocationTargetException
           at sun.reflect.GeneratedMethodAccessor26.invoke(Unknown Source)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
           at java.lang.reflect.Method.invoke(Method.java:498)
           at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:413)
           at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:336)
           ... 140 more
  Caused by: java.lang.ClassFormatError: Duplicate method name&signature in class file org/springframework/scheduling/quartz/SchedulerFactoryBean$$EnhancerBySpringCGLIB$$bee87fe8$$EnhancerBySpringCGLIB$$6bb26669
           at java.lang.ClassLoader.defineClass1(Native Method)
           at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
           ... 145 more

1 个答案:

答案 0 :(得分:0)

这绝对是cglib中的一个错误。似乎它当前没有确定类型层次结构中的方法等于另一个方法。您是否将Java 8与接口中的默认方法结合使用?

Cglib并没有真正针对现代Java版本进行测试,只经历了很少的维护。较新的功能有时会在使用库时造成麻烦。