返回顶部

收藏

javassist javassist.NotFoundException: xxx问题解决

更多

javassist的ClassPool.getCtClass(xx)执行是报错:

08-Feb-2017 16:45:01.386 严重 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal Context [] startup failed due to previous errors
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_60-ea]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_60-ea]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_60-ea]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422) ~[na:1.8.0_60-ea]
    at com.jd.coo.sa.mybatis.plugins.utils.ReflectionUtils.newInstance(ReflectionUtils.java:94) ~[mybatis-plugins-1.0.6.jar:na]
    ... 77 common frames omitted
Caused by: java.lang.RuntimeException: Can't found class
    at com.jd.coo.sa.mybatis.plugins.pagination.JavassistPageAdaptor.<init>(JavassistPageAdaptor.java:65) ~[mybatis-plugins-1.0.6.jar:na]
    ... 82 common frames omitted
Caused by: javassist.NotFoundException: com.jd.coo.sa.mybatis.plugins.pagination.PageAdapter
    at javassist.ClassPool.get(ClassPool.java:450) ~[javassist-3.19.0-GA.jar:na]
    at javassist.ClassPool.getCtClass(ClassPool.java:515) ~[javassist-3.19.0-GA.jar:na]
    at com.jd.coo.sa.mybatis.plugins.pagination.JavassistPageAdaptor.<init>(JavassistPageAdaptor.java:43) ~[mybatis-plugins-1.0.6.jar:na]
    ... 82 common frames omitted

错误是找不到类, 但是类确实在jar包中存在, 解决此问题的办法是手动将类的ClassPath添加ClassPool中, 如下代码:

Model model = new Model();
ClassPool pool = ClassPool.getDefault();
ClassClassPath ccpath = new ClassClassPath(model.getClass());
pool.insertClassPath(ccpath);
CtClass ctClass = pool.get("com.project.Model");

标签:java,javassist

收藏

1人收藏

支持

1

反对

0

相关聚客文章
  1. obaby 发表 2018-01-04 08:57:51 Javassist
  2. admin 发表 2013-11-13 04:38:59 javassist这货到底干嘛的?
  3. coderbee 发表 2017-07-19 14:41:16 Javassist 字节码操作库
  4. hongjiang 发表 2014-09-04 08:53:47 tomcat-connector的微调(5): keep-alive相关的参数
  5. TiuVe2 发表 2017-08-01 16:01:54 关于烂代码的那些事(上)
  6. bluedavy 发表 2014-09-18 04:07:42 内部的一次编程比赛
  7. TiuVe2 发表 2017-08-06 00:46:48 关于烂代码的那些事( 中 )
  8. Fowler Zhang 发表 2014-09-22 10:21:45 常见Java面试题 – 第三部分:重载(overloading)与重写(overriding)
  9. TiuVe2 发表 2017-08-10 06:24:33 Java 引用类型简述
  10. 博主 发表 2014-07-05 08:13:08 FastJson 自定义Serialize、Parser
  11. 加多 发表 2017-08-26 01:39:21 JDK8中新增原子性操作类LongAdder
  12. 博主 发表 2014-09-14 14:42:26 Java运行时区域是这样的

发表评论