關於javassist.NotFoundException


avassist可以用於反射獲取方法參數名稱,項目中用到,測試用例通過,當發布到tomcat時報錯
javassist.NotFoundException: xxx.xxx.xxxService
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.(推薦)

ClassPool pool = ClassPool.getDefault();
   ClassClassPath classPath = new ClassClassPath(this.getClass());
   pool.insertClassPath(classPath);
ClassPool pool = ClassPool.getDefault();
pool.appendClassPath("E:\\xxx\\xxx\\target\\xxx_war\\WEB-INF\\lib\\xxx_jar-0.0.1-SNAPSHOT.jar");

2.更多參見:

http://www.csg.is.titech.ac.jp/~chiba/javassist/tutorial/tutorial.html

轉載於:https://my.oschina.net/idiotsky/blog/208734


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM