Cannot proxy target class because CGLIB2 is not available .Add CGLIB to the class path or specify proxy interfaces…..

报错:Cannot proxy target class because CGLIB2 is not available .Add CGLIB to the class path or specify proxy interfaces…..

问题原因:

Spring框架,如果类实现了接口,就使用JDK的动态代理生成代理对象,如果这个类没有实现任何接口,就使用CGLIB生成代理对象。

解决办法有两种:

方案一让类实现某个接口;
方案二导入CGLIB包;

cglib是一个开源项,一个强大的,高性能,高质量的Code生成类库,它可以在运行期扩展Java类与实现Java接口。

本工程用的spring3.0.7,导入cglib-3.1.jar

继续报错:

Initialization of bean failed; nested exception is java.lang.IncompatibleClassChangeError: net/sf/cglib/core/DebuggingClassWriter

换成cglib-2.3.jar

问题解决

原文地址:https://www.cnblogs.com/mengjinluohua/p/7473411.html