zoukankan      html  css  js  c++  java
  • org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; 前言中不允许有内容。

    spring boot项目启动报错,错误提示如下:

    nested exception is org.springframework.beans.factory.BeanCreationException:
    Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]:
    Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException:
    Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception;
    nested exception is org.springframework.core.NestedIOException: Failed to parse config resource:
    class path resource [mybatis-config.xml]; nested exception is org.apache.ibatis.builder.BuilderException:
    Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException:
    Error creating document instance. Cause: org.xml.sax.SAXParseException;
    lineNumber: 1; columnNumber: 1; 前言中不允许有内容。;

     

    仔细肉眼检查了mybatis-config.xml和各个新提交的mapper映射文件,都看不出什么问题,百思不得其解。

    经大师提点,怀疑是字符编码问题,于是把新提交的mapper文件复制出来用notepad打开,点击格式菜单,发现这几个文件的编码格式都是 “以UTF-8格式编码”,改成 “以UTF-8无BOM格式编码”,保存之后再复制回来,启动项目,报错消失。

    原来这几个mapper文件都是由模板生成,模板生成出来的文件是UTF-8带BOM格式,java只认UTF-8无BOM格式。

     大多数记事本工具(Emedit等)默认是以utf-8 BOM方式,会在文件中加入BOM头,导致这个错误:

     Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1;前言中不允许有内容。

    用notepad打开,格式改成 “以UTF-8无BOM格式编码”即可。

  • 相关阅读:
    [Cypress] install, configure, and script Cypress for JavaScript web applications -- part4
    [Angular] Lazy Load CSS at runtime with the Angular CLI
    [置顶] 半年的工作总结
    分享4个未注册*sdn域名
    Windows 已在 DImageProcess.exe 中触发一个断点。
    Foundation: Binary Search
    HDU 3016 Man Down (线段树+dp)
    网络智能和大数据公开课Homework3 Map-Reduce编程
    centos 6.2 关闭 IPV6
    [置顶] 【Git入门之八】分支管理
  • 原文地址:https://www.cnblogs.com/zhangcybb/p/6529597.html
Copyright © 2011-2022 走看看