返回顶部

收藏

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