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

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

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; 前言中不允许有内容。;

原来是在src/main/resources下的applicationContext-jms-producer.xml文件都是UTF-8带BOM格式,java只认UTF-8格式。

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

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

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

猜你喜欢

转载自blog.csdn.net/weixin_42595331/article/details/86026401