Caused by: org.xml.sax.SAXParseException: 外部 DTD: 无法读取外部 DTD 'mybatis-generator-config_1_0.dtd'

1.环境:

  JDK 1.8

  IntelliJ IDEA 2019.3.2 (Community Edition)

  Build #IC-193.6015.39, built on January 21, 2020
  Runtime version: 11.0.5+10-b520.30 amd64

2.现象:

  添加 mybatis 的 generatorConfig.xml 后报错

Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 67; 外部 DTD: 无法读取外部 DTD 'mybatis-generator-config_1_0.dtd', 因为 accessExternalDTD 属性设置的限制导致不允许 'http' 访问。
    at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:263) ~[mybatis-3.5.3.jar:3.5.3]
    at org.apache.ibatis.parsing.XPathParser.<init>(XPathParser.java:127) ~[mybatis-3.5.3.jar:3.5.3]
    at org.apache.ibatis.builder.xml.XMLMapperBuilder.<init>(XMLMapperBuilder.java:80) ~[mybatis-3.5.3.jar:3.5.3]
    at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:592) ~[mybatis-spring-2.0.3.jar:2.0.3]
    ... 70 common frames omitted
Caused by: org.xml.sax.SAXParseException: 外部 DTD: 无法读取外部 DTD 'mybatis-generator-config_1_0.dtd', 因为 accessExternalDTD 属性设置的限制导致不允许 'http' 访问。
    at java.xml/com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:204) ~[na:na]
    at java.xml/com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:178) ~[na:na]
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:400) ~[na:na]
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327) ~[na:na]
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1471) ~[na:na]
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.dispatch(XMLDocumentScannerImpl.java:1148) ~[na:na]
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.next(XMLDocumentScannerImpl.java:1040) ~[na:na]
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:943) ~[na:na]
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:605) ~[na:na]
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:541) ~[na:na]
    at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:888) ~[na:na]
    at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:824) ~[na:na]
    at java.xml/com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141) ~[na:na]
    at java.xml/com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:246) ~[na:na]
    at java.xml/com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:339) ~[na:na]
    at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:261) ~[mybatis-3.5.3.jar:3.5.3]
    ... 73 common frames omitted

3.解决方法:

  百度到的

  解决方法一:

    Fetch external resource 到本地 如:https://blog.csdn.net/qq_35598865/article/details/88936975

  解决方法二:

    修改javax.xml.accessExternalSchema的值 如:https://blog.csdn.net/dingshuo168/article/details/103317453

在你的%JAVA_HOEE%\jre\lib\ 目录下,新建一个文件jaxp.properties,内容:

javax.xml.accessExternalSchema=all
javax.xml.accessExternalDTD=all

就可以解决了

尝试之后都没用。

解决方法:

  报错时候的位置。

 

 

 不报错的位置。

 

修改了一下generatorConfig.xml的位置,程序就不报错了。

 

posted @ 2020-02-06 17:49  Alex-Zeng  阅读(4894)  评论(1编辑  收藏  举报