在Javassist学习时遇到的javassist.NotFoundException问题的解决办法
//运行时会报错的原代码:
ClassPool pool = ClassPool.getDefault();
CtClass cc = pool.get(Emp.class.getName());
//更改后可以运行不报错的代码:
ClassPool pool = ClassPool.getDefault();
pool.insertClassPath(new ClassClassPath(Emp.class));
CtClass cc = pool.get(Emp.class.getName());
与原来程序相比,在新程序的中间添加了insertClassPath()这一方法,猜测是jdk版本的问题。在加入该行代码后运行无误。
————————————————
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/weixin_43900321/article/details/105189867