解决MalformedByteSequenceException: 2 字节的 UTF-8 序列的字节 2 无效。

问题描述:

在springBoot 中为了维户开发方便,将***Mapper.java   和*** Mapper.xml 放在同一目录下,由于没有配置好,结果运行时报了

MalformedByteSequenceException: 2 字节的 UTF-8 序列的字节 2 无效。

ERROR:   nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: 2 字节的 UTF-8 序列的字节 2 无效。

解决办法:

1、网上说是由于文件编码不对 引起的,我用了笨方法,将所有文件(*.java *.xml *.yml 等等)都另存为uft-8 但还是一样报错

2、网上说打包时pom.xml 加上-Dfile.encoding=utf-8 如下

    <build>
        <finalName>${project.name}</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                <fork>true</fork>
                <!-- spring-boot:run 中文乱码解决 -->
                <jvmArguments>-Dfile.encoding=UTF-8</jvmArguments>
                </configuration>
            </plugin>
        </plugins>
    </build>

但还是无效

3、最终经过排查,是由于 mapper-locations 配置引起的。

错误的配置:mapper-locations: classpath:com/qen/dao/**/*

正确的配置:mapper-locations: classpath:com/qen/dao/**/*.xml

没有看源代码,猜测mapper-locations: 加载文件如果解析不出来 就报错,因为 ***Mapper.class 是二进制文件,肯定读不出来

希望能帮到您!

 

  • 7
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值