使用CGLIB动态代理时遇到的与asm冲突问题

使用CGLIB进行动态代理时报了如下错误

Exception in thread "main" java.lang.ExceptionInInitializerError
	at common.proxy.CglibProxyExample.getProxy(CglibProxyExample.java:18)
	at test.main(test.java:12)
Caused by: java.lang.IllegalStateException: Unable to load cache item
	at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:79)
	at org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34)
	at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:130)
	at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:315)
	at org.springframework.cglib.core.KeyFactory$Generator.create(KeyFactory.java:237)
	at org.springframework.cglib.core.KeyFactory.create(KeyFactory.java:184)
	at org.springframework.cglib.core.KeyFactory.create(KeyFactory.java:160)
	at org.springframework.cglib.proxy.Enhancer.(Enhancer.java:104)
	... 2 more
Caused by: java.lang.IncompatibleClassChangeError: class org.springframework.cglib.core.DebuggingClassWriter has interface org.springframework.asm.ClassVisitor as super class
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at org.springframework.cglib.core.DefaultGeneratorStrategy.getClassVisitor(DefaultGeneratorStrategy.java:30)
	at org.springframework.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:24)
	at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:354)
	at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:106)
	at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:104)
	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)
	... 9 more

在网上搜了一圈大部分都说时cglib与asm包冲突了,要将cglib包降到2.2版本或者直接引入最新的asm的jar包。

我偷了个懒,直接尝试在maven中引入spring-asm。成功搞定这个冲突


      org.springframework
      spring-asm
      ${spring.version}

你可能感兴趣的:(Java,SSM)