使用CGlib出现java.lang.NoClassDefFoundError: org/objectweb/asm/Type异常
在学习使用CGlib生成动态代理对象,项目的源代码也很简单:
package proxy; import java.lang.reflect.Method; import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy; public class CGlibProxy implements MethodInterceptor { @SuppressWarnings("unchecked")
public <T> T getProxy(Class<T> clazz) {
return (T) Enhancer.create(clazz, this);
} @Override
public Object intercept(Object obj, Method method, Object[] args,
MethodProxy proxy) throws Throwable {
before();
Object result = proxy.invokeSuper(obj, args);
after();
return result;
} private void before() {
System.out.println(" before "); } private void after() {
System.out.println(" after ");
} public static void main(String[] args) {
CGlibProxy cGlibProxy = new CGlibProxy();
Hello helloProxy = cGlibProxy.getProxy(HelloImp.class);
helloProxy.say("Bob"); }
}
由于CGlib是第三方的类库,所以要在项目路径中引入CGlib的jar包版本选择了2.2:

不过在运行的时候出现了异常:
Exception in thread "main" java.lang.NoClassDefFoundError: org/objectweb/asm/Type
at net.sf.cglib.core.TypeUtils.parseType(TypeUtils.java:180)
at net.sf.cglib.core.KeyFactory.<clinit>(KeyFactory.java:66)
at net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java:69)
at proxy.CGlibProxy.getProxy(CGlibProxy.java:13)
at proxy.CGlibProxy.main(CGlibProxy.java:36)
Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.Type
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 5 more
报错显示有找不到的类,上网查了以下知道了很多java字节码操作和分析的第三方类库都引用了asm.jar文件,由于工程不是Maven管理的,无法解决以来传递问题,所以要手动引入asm.jar文件。把asm.jar文件添加到项目路径类,运行,然后就正常了。
参考:http://javabeat.net/java-lang-noclassdeffounderror-orgobjectwebasmclassvisitor/
使用CGlib出现java.lang.NoClassDefFoundError: org/objectweb/asm/Type异常的更多相关文章
- java.lang.NoClassDefFoundError: org/objectweb/asm/Type
Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/objectweb/asm/ ...
- Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/objectweb/asm/Type
问题描述 将项目挂载到 Myeclipse 的 tomcat 上,启动 tomcat ,报错“Initialization of bean failed; nested exception is ja ...
- Caused by: java.lang.NoClassDefFoundError: org/objectweb/asm/Type
使用 proxy-target-class="true" 强制配置了 cglib 代理,于是包上面的错误,加入了 asm.jar 报也一样报错. 错误原因是,lib 中有两个cgl ...
- 【错误总结】java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor
运行环境 JDK1.7 64位 Window 7 64位 Ecplise Java EE IDE Struts 2.3.9 Tomcat 7 说明: ...
- Exception starting filter struts2 java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor
按教程,使用Convention插件进行配置 教程中说只要加入struts2-convention-plugin-2.3.4.1.jar这个jar包就可以使用. 按照这种方法部署后,启动tomcat报 ...
- SSH整合后tomcat启动报错SEVERE: Exception starting filter struts2 java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor
错误信息: SEVERE: Exception starting filter struts2 java.lang.NoClassDefFoundError: org/objectweb/asm/C ...
- CGLib缺少jar出现 java.lang.ClassNotFoundException: org.objectweb.asm.Type
CGLib实现动态代理区别于JDK动态代理,不需要目标类实现任何接口,是通过生成代理类子类的方式,而且据说速度要快于JDK动态代理.所以我想要试验一下CGlib的动态代理,网上找了些例子,自己动手写了 ...
- 解决java.lang.NoClassDefFoundError: org/objectweb/asm/util/TraceClassVisitor
方案一: <dependency> <groupId>asm</groupId> <artifactId>asm-all</artifactId& ...
- org/objectweb/asm/Type异常解决办法
关于java.lang.NoClassDefFoundError: org/objectweb/asm/Type 调试SPRING MVC(或者整合SSH)的时候遇到了org/objectweb/as ...
随机推荐
- python调用cmd显示中文乱码及调用cmd命令
os.system('dir') 解决方法加上 os.system('chcp 65001') ____________________________________________________ ...
- 简单快捷使用Git
1.简介和安装Git是世界上目前最先进的分布式版本控制系统.安装:https://git-for-windows.github.io下载.设置姓名和email:git config --global ...
- <Dare To Dream 团队>第二次作业:基于B/S的家教管理系统
团队项目GitHub仓库地址:https://github.com/Sophur/Team-Project.git 为其他团队评分结果: 小组名 N A B C D 总分 平均分 Blue Flk ...
- Linux Tomcat安装部署项目
一.上传Tomcat服务器
- java 虚拟机栈
与程序计数器一样,Java虚拟机栈也是线程私有的,他的生命周期与线程相同.虚拟机栈描述的是Java执行的内存模型:每个方法被执行的时候都会同时创建一个栈帧用于存储局部变量表,操作栈,动态链接,方法出口 ...
- java集合: jdk1.8的hashMap原理简单理解
HashMap的数据结构 HashMap是数组+链表+红黑树(JDK1.8增加了红黑树部分)实现的,他的底层结构是一个数组,而数组的元素是一个单向链表.HashMap默认初始化的是一个长度为16位的数 ...
- TZOJ 3820 Revenge of Fibonacci(大数+trie)
描述 The well-known Fibonacci sequence is defined as following: Here we regard n as the index of the F ...
- Springboot08-项目单元测试(接口测试)
Springboot08-项目单元测试(接口测试) 前言 1-本文重点在于源码层面,分析Springboot单元测试的使用,对于其中的注解.方法等,不会仔细分析: 2-本文项目实例相关配置:Java- ...
- Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/jms/JMSContext
参考链接 : https://blog.csdn.net/angus_Lucky/article/details/82811946?utm_source=blogxgwz7 org.springfra ...
- go语言 http学习
net/http库学习 概念 处理器 处理器:拥有ServeHTTP方法的接口(任何类型) 签名:ServeHTTP(http.ResponseWriter, *http.Request) Respo ...