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 ...
随机推荐
- Verilog HDL实用教程笔记
Verilog HDL实用教程笔记 DRC - Design Rule Check 几何规则检查ERC - Electrical Rule Check 电学规则检查自动参数提取LVS - Logic ...
- Python3.6全栈开发实例[019]
19.干掉主播.现有如下主播收益信息, 按照要求, 完成相应操作:(1)计算主播平均收益值 sum = 0 for i in zhubo.values(): sum +=i print(round(s ...
- C#窗口的Load事件与Shown事件的差别
Load:在第一次显示窗口前发生. <pre name="code" class="csharp"> private void Form1_Load ...
- 剑指offer 面试62题
面试62题: 题目:圆圈中最后剩下的数字 题:0,1,...,n-1这n个数字排成一个圆圈,从数字0开始,每次从这个圆圈里删除第m个数字.求出这个圆圈里剩下的最后一个数字. 解题思路:约瑟夫环问题,可 ...
- [笔记]一道C语言面试题:IPv4字符串转为UInt整数
题目:输入一个IPv4字符串,如“1.2.3.4”,输出对应的无符号整数,如本例输出为 0x01020304. 来源:某500强企业面试题目 思路:从尾部扫描到头部,一旦发现无法转换,立即返回,减少无 ...
- paramiko 模块安装和使用
一.Centos安装Paramiko 1.安装组件 yum install openssl openssl-devel python-dev pycrypto -y yum install zlib- ...
- Android sdk manager加载缓慢或加载不出来
1.打开android sdk manager 2.打开tool->options,如图所示 3.将Proxy Settings 里的HTTP Proxy Server和HTTP Proxy P ...
- 所有文本的 attributes 枚举,NSAttributedString
// Predefined character attributes for text. If the key is not in the dictionary, then use the defau ...
- VMWare中安装windowsXP遇到的问题
XP系统安装 1.安装Windows和安装linux不一样,创建虚拟机完成后Linux自动根据硬盘进行系统安装,不需要提前分区.而windows必须进行提前分区,这个分区是在虚拟磁盘上完成的,就是你创 ...
- WEB-INF有关的目录路径总结、转向方式: forward 重定向方式: Redirect
WEB-INF有关的目录路径总结 1.资源文件只能放在WebContent下面,如 CSS,JS,image等.放在WEB-INF下引用不了. 2.页面放在WEB-INF目录下面,这样可以限制访问,提 ...