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(当我没说)

引用:试水流连

原文地址:https://www.cnblogs.com/ldy-blogs/p/8671863.html

时间: 2024-08-08 12:25:18

SpringBoot使用devtools导致的类型转换异常的相关文章

Android的debug.keystore拒绝访问导致的生成异常及解决方案

构建Android应用程序的时候输出异常:[apkbuilder] keytool 错误: java.io.FileNotFoundException: C:\Users\my\.android\debug.keystore(拒绝访问.)导致BUILD FAILED. 异常原因: Android要求所有的应用程序必须有签名,否则就不会安装该程序.而在我们开发过程中,默认生成和使用debug.keystore(所以平时根本不会注意有这么个玩意),debug.keystore默认有效期为一年,换句话

YS VTM模块存在格式化字符串漏洞,可导致VTM进程异常退出【高危】

YS VTM模块存在格式化字符串漏洞,可导致VTM进程异常退出[高危] 问题描述:          YS VTM模块开放对外监听端口(8554和8664),此次使用sulley fuzzing框架对监听在8664端口的私有二进制协议进行测试,以检测可能发生的各种问题.在该协议中,客户端会向8664端口发送一个二进制+文本格式的报文,对该报文格式的各个字段进行fuzzing,发现当向服务端的VTM进程传入格式化字符串时会崩溃并退出. 测试步骤: 1.  分别在客户机和服务器安装sulley fu

oracle所在磁盘空间不足导致了数据库异常

oracle所在磁盘空间不足导致了数据库异常.需要减小数据文件的大小来解决. 1.检查数据文件的名称和编号 select file#,name from v$datafile; 2.看哪个数据文件所占的空间最大,根据该数据文件的编号查看该数据文件的最大数据块数 select max(block_id) from dba_extents where file_id=8; 查询结果 3.计算该表空间的实际占用空间.(不是物理文件的大小) 查看每个数据块的大小 show parameter db_bl

SpringBoot配置devtools实现热部署

SpringBoot配置devtools实现热部署 spring为开发者提供了一个名为spring-boot-devtools的模块来使Spring Boot应用支持热部署,提高开发者的开发效率,无需手动重启Spring Boot应用. devtools的原理 深层原理是使用了两个ClassLoader,一个Classloader加载那些不会改变的类(第三方Jar包),另一个ClassLoader加载会更改的类,称为restart ClassLoader,这样在有代码更改的时候,原来的resta

最近走过的坑 :slf4j 多个实现 hibernate 类型转换异常 bean依赖问题

最近走过的坑 slf4j 多个实现 主要是maven依赖中存在多个slf4j的实现类,在引入的依赖中排除对应的依赖就可以 <dependency> <groupId>xxxxxx</groupId> <artifactId>xxxxxx</artifactId> <version>1.0.0</version> <exclusions> <exclusion> <groupId>org.

在项目中配置PageHelper插件时遇到类型转换异常

PageHelper是一种常用的分页工具,按照常规方法在mybatis的配置文件中整合它: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> &l

SpringBoot:如何优雅地处理全局异常?

SpringBoot:如何优雅地处理全局异常? 之前用springboot的时候,只知道捕获异常使用try{}catch,一个接口一个try{}catch,这也是大多数开发人员异常处理的常用方式,虽然屡试不爽,但会造成一个问题,就是一个Controller下面,满屏幕的try{}catch,看着一点都不优雅,一点都不符合×××的气质,憋了这么久,×××今天终于决定对所有异常实施统一处理的方案. 开发准备 JDK8.正常的springboot项目 代码编写 通用异常处理 其实Spring系列的项目

SpringBoot之devtools热部署

spring-boot-devtools是一个为开发者服务的一个模块,其中最重要的功能就是自动应用代码更改到最新的App上面去.原理是在发现代码有更改之后,重新启动应用,但是比速度比手动停止后再启动还要更快,更快指的不是节省出来的手工操作的时间. 其深层原理是使用了两个ClassLoader,一个Classloader加载那些不会改变的类(第三方Jar包),另一个ClassLoader加载会更改的类,称为  restart ClassLoader ,这样在有代码更改的时候,原来的restart

springboot 添加mybatisjar包发生的异常问题?

一.pro.xml文件中,添加mybatisjar包 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://mav