spring boot classloader

栏目: Java · 发布时间: 6年前

内容简介:最近闲暇时写了一个hessian 小测试的工具,为了方便使用了spring boot。该测试工具最关键的步骤是动态加载每个测试模块对应的hessian api的jar包。开始的加载代码为:在IDE直接运行spring boot 的main函数,every thing is ok !当我将项目编译成jar包,上传到测试环境执行:java -jar 后,发现通过URLClassLoader 无法找到hessian的类,一顿调试排查后,IDE 依旧OK,命令起到你jar 依旧无法工作。这是我考虑到是不是sprin

最近闲暇时写了一个hessian 小测试的工具,为了方便使用了spring boot。该测试 工具 最关键的步骤是动态加载每个测试模块对应的hessian api的jar包。开始的加载代码为:

URLClassLoader loader=new URLClassLoader(new URL[]{new URL("file:"+jarPathStrategy.fileStorePath(moduleName,jarname))});
loader.loadClass(className);

在IDE直接运行spring boot 的main函数,every thing is ok !

当我将项目编译成jar包,上传到测试环境执行:java -jar 后,发现通过URLClassLoader 无法找到hessian的类,一顿调试排查后,IDE 依旧OK,命令起到你jar 依旧无法工作。这是我考虑到是不是spring boot的classloader 比较特殊,不是systemclassloader。google一下,果不其然跟我想的一样,spring boot 的classloader 继承体系有所变化。具体参见此大神的实验( http://hengyunabc.github.io/s... )。遂修改代码:

URLClassLoader loader=new URLClassLoader(new URL[]{new URL("file:"+jarPathStrategy.fileStorePath(moduleName,jarname))},parentClassLoader);
loader.loadClass(className);请输入代码

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Programming PHP

Programming PHP

Rasmus Lerdorf、Kevin Tatroe、Peter MacIntyre / O'Reilly Media / 2006-5-5 / USD 39.99

Programming PHP, 2nd Edition, is the authoritative guide to PHP 5 and is filled with the unique knowledge of the creator of PHP (Rasmus Lerdorf) and other PHP experts. When it comes to creating websit......一起来看看 《Programming PHP》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

URL 编码/解码
URL 编码/解码

URL 编码/解码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具