org.xml.sax.SAXParseException:序言中不允许内容

时间:2019-03-22 16:58:53

标签: mybatis spring-mybatis

这是我的项目demo,我想使用MyBatis xml配置。但是我遇到了这样的SAXParseException错误

const localeCompare = Intl.Collator('en', { sensitivity: 'base' }).compare;
function includesByIgnoreCase(predicate) {
  if (this.filter(predicate).length > 0) {
    return true;
  }
  return false;
};

const value2 = ['hElLo', 'world', 'foo', 'Hello Wolrd'];

console.log(
  includesByIgnoreCase.call(
    value2,
    e => localeCompare(e, 'hello world') !== 0
  )
);

这是我的mapper xml文件:

Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
    at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:260)
    at org.apache.ibatis.parsing.XPathParser.<init>(XPathParser.java:126)
    at org.apache.ibatis.builder.xml.XMLMapperBuilder.<init>(XMLMapperBuilder.java:80)
    at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:519)
    ... 56 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:177)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:400)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327)
    at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1472)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:994)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:602)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:505)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:842)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:771)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:243)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:339)
    at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:258)
    ... 59 more

1 个答案:

答案 0 :(得分:2)

问题在于您的mybatis配置:

mybatis:
  configuration:
    map-underscore-to-camel-case: true
  type-aliases-package: com.ryanqy.entity
  mapper-locations: mapper

mapper-locations更改为:

  mapper-locations: mapper/UserMapper.xml
  #OR
  mapper-locations: mapper/*.xml

如果进行更改,则会在映射器XML中收到缺少DOCTYPE的错误,因此请添加类似的内容

<!DOCTYPE mapper
  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-mapper.dtd">