SpringBoot使用devtools导致的类型转换异常
- 遇到的问题:
SpringBoot项目中的热部署引发的血的教训,报错代码位置:
1 XStream xStream1 = new XStream();
2 xStream1.autodetectAnnotations(true);
3 xStream1.alias("InterBOSS", InterBossHeader.class);
4 InterBossHeader resp = (InterBossHeader) xStream1.fromXML(response);项目中的pom配置:
1 <dependency>
2 <groupId>org.springframework.boot</groupId>
3 <artifactId>spring-boot-devtools</artifactId>
4 <scope>runtime</scope>
5 </dependency> - 问题的分析:
以上配置发现同样的类型(InterBossHeader)竟然出现了类型转换异常!WQNMMP—。—
分析出ClassLoader不同导致的类型转换异常,Spring的dev-tools为了实现重新装载class自己实现了一个类加载器,来加载项目中会改变的类,方便重启时将新改动的内容更新进来,其实其中官方文档中是有做说明的:
1 By default, any open project in your IDE will be loaded using the
2 “restart” classloader, and any regular .jar file will be loaded using
3 the “base” classloader. If you work on a multi-module project, and not
4 each module is imported into your IDE, you may need to customize
5 things. To do this you can create a
6 META-INF/spring-devtools.properties file.
7 The spring-devtools.properties file can contain restart.exclude. and
8 restart.include. prefixed properties. The include elements are items
9 that should be pulled up into the “restart” classloader, and the
10 exclude elements are items that should be pushed down into the “base”
11 classloader. The value of the property is a regex pattern that will be
12 applied to the classpath. - 解决办法:
第一种解决方案:在resources目录下面创建META_INF文件夹,然后创建spring-devtools.properties文件,文件加上类似下面的配置:
restart.exclude.companycommonlibs=/mycorp-common-[\w-]+.jar
restart.include.projectcommon=/mycorp-myproj-[\w-]+.jar
第二种解决方案:不使用spring-boot-devtools(当我没说)
引用:试水流连
SpringBoot使用devtools导致的类型转换异常的更多相关文章
- springboot中redis取缓存类型转换异常
异常如下: [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested ...
- weblogic启动节点服务java.lang.ClassCastException:com.octestring.vde.backend.BackendRoot cannot be cast to com.octestring.vde.backend.standard.BackendStandard类型转换异常
weblogic启动节点服务器报错,java.lang.ClassCastException:com.octestring.vde.backend.BackendRoot cannot be cast ...
- springboot之DevTools热部署的简单原理解析
IDEA新建springboot选择DevTools springboot-devtools模块能够实现热部署,添加类.添加方法,修改配置文件,修改页面等,都能实现热部署. 原理就是重启项目,但比手动 ...
- 最近走过的坑 :slf4j 多个实现 hibernate 类型转换异常 bean依赖问题
最近走过的坑 slf4j 多个实现 主要是maven依赖中存在多个slf4j的实现类,在引入的依赖中排除对应的依赖就可以 <dependency> <groupId>xxxxx ...
- Oracle 监听器日志文件过大导致监听异常
Oracle 监听器日志文件过大导致监听异常 db版本:11.2.0.1 os版本:windows2008 现象: 应用异常,无法连接数据库.登陆数据库服务器,查看监听已经断掉.尝试重启监听,重启失败 ...
- oracle所在磁盘空间不足导致了数据库异常
oracle所在磁盘空间不足导致了数据库异常.需要减小数据文件的大小来解决. 1.检查数据文件的名称和编号 select file#,name from v$datafile; 2.看哪个数据文件所占 ...
- Android的debug.keystore拒绝访问导致的生成异常及解决方案
构建Android应用程序的时候输出异常:[apkbuilder] keytool 错误: java.io.FileNotFoundException: C:\Users\my\.android\de ...
- 关于FusionCharts图表宽度width的设置问题导致图表显示异常的解决办法
关于FusionCharts图表宽度width的设置问题导致图表显示异常的解决办法 题设: 经常使用FusionCharts图表的朋友可能会遇到这个问题.就是在FusionCharts显示的时候有时候 ...
- 堆内存泄漏移除导致tcp链接异常高
故障现象: 1:活动前端Nginx服务器TCP连接数到1万多 2:活动后端Tomcat其中1台TCP连接数达4千,并且CPU瞬间到780%(配置8核16G),内存正常 3:重启后端Tomcat后,TC ...
随机推荐
- windows server2003/2008中权限账户
在windows server 2003与windows server 2008 R2中,查看文件夹权限时,尤其是用cacls命令查看时,经常会见nt authority system这样的用户信息. ...
- JavaScript+css+ div HTML遮罩層效果
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Test</title ...
- Python替换文件内容
#!/usr/bin/env python import fileinput for line in fileinput.input('fansik',inplace=1): line = line. ...
- 【WEB HTTP】集成点:网关、隧道及中继
网关:网关可以作为某种翻译器使用,它抽象出了一种能够到达资源的方法.网关是资源与应用程序之间的粘合剂. 在不同http版本之间进行转换的Web代理和网关一样,他们会执行复杂的逻辑,以便在各个端点之间进 ...
- 根据GUID获取设备信息
#include <windows.h> #include <setupapi.h> #include <objbase.h> #include <initg ...
- JS 操作复制剪切粘贴
测试了很多次之后,虽然有点细碎的突破,但还是想说,麻辣隔壁... 众所周知使用 oncut/oncopy/onpaste 监听剪切板,采用 window.clipboardData 并不是适用于大多浏 ...
- Nginx配置指令的执行顺序
rewrite阶段 rewrite阶段是一个比较早的请求处理阶段,这个阶段的配置指令一般用来对当前请求进行各种修改(比如对URI和URL参数进行改写),或者创建并初始化一系列后续处理阶段可能需要的Ng ...
- Tooltip表单验证的注册表单
在线演示 本地下载
- [转载]Runtime详解
Runtime的特性主要是消息(方法)传递,如果消息(方法)在对象中找不到,就进行转发,具体怎么实现的呢.我们从下面几个方面探寻Runtime的实现机制. Runtime介绍 Runtime消息传 ...
- avaweb学习总结(八)——HttpServletResponse对象(二)
一.HttpServletResponse常见应用——生成验证码 1.1.生成随机图片用作验证码 生成图片主要用到了一个BufferedImage类,