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);请输入代码

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

查看所有标签

猜你喜欢:

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

Data-intensive Text Processing With Mapreduce

Data-intensive Text Processing With Mapreduce

Jimmy Lin、Chris Dyer / Morgan and Claypool Publishers / 2010-4-30 / USD 40.00

Our world is being revolutionized by data-driven methods: access to large amounts of data has generated new insights and opened exciting new opportunities in commerce, science, and computing applicati......一起来看看 《Data-intensive Text Processing With Mapreduce》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

html转js在线工具
html转js在线工具

html转js在线工具