关于javassist.NotFoundException

假如想象 提交于 2020-01-06 17:06:03

【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>>

javassist可以用于反射获取方法参数名称,项目中用到,测试用例通过,当发布到tomcat时报错

javassist.NotFoundException: xxx.xxx.xxxService

 

 
  1. ClassPool pool = ClassPool.getDefault();

  2. CtClass cls = pool.get(clazz.getName()); // 此处报异常


 

javassist官网对此有如下说明:

The default ClassPool returned by a static method ClassPool.getDefault() searches the same path that the underlying JVM (Java virtual machine) has. If a program is running on a web application server such as JBoss and Tomcat, the ClassPoolobject may not be able to find user classes since such a web application server uses multiple class loaders as well as the system class loader. In that case, an additional class path must be registered to the ClassPool.

解决此异常的方法:

1.(推荐)

 

 
  1. ClassPool pool = ClassPool.getDefault();

  2. ClassClassPath classPath = new ClassClassPath(this.getClass());

  3. pool.insertClassPath(classPath);


 

2.

 
  1. ClassPool pool = ClassPool.getDefault();

  2. pool.appendClassPath("E:\\xxx\\xxx\\target\\xxx_war\\WEB-INF\\lib\\xxx_jar-0.0.1-SNAPSHOT.jar");


 

转自:http://www.codeweblog.com/%E5%85%B3%E4%BA%8Ejavassist-notfoundexception/

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!