有没有大佬遇到过
今天下载 mybatis源码 然后写了个 demo,遇到这个问题 网上说的,在 jar/lib 加个配置文件没有用呀
引入本地的dtd会变成不允许 file 类型的
完全按官网步骤来的
测试方法
public static void main(String[] args) throws IOException {
String resource = "mybatis-config.xml";
InputStream inputStream = Resources.getResourceAsStream(resource);
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
try (SqlSession session = sqlSessionFactory.openSession()) {
UserEntity userEntity = session.selectOne("com.yjl.demo1.mapper.UserMapper.selectAllByUserName", "admin");
System.out.println(userEntity.toString());
}
}
mybatis-config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="com.mysql.cj.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://xxx:3306/test1?serverTimezone=UTC&useSSL=false"/>
<property name="username" value="root"/>
<property name="password" value="20170326Yuan.."/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="mapper/UserMapper.xml"/>
</mappers>
</configuration>
Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException:
### Error building SqlSession.
### Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 49; 外部 DTD: 无法读取外部 DTD 'mybatis-3-config.dtd', 因为 accessExternalDTD 属性设置的限制导致不允许 'http' 访问。
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:80)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:64)
at com.yjl.demo1.Lean1.main(Lean1.java:16)
Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 49; 外部 DTD: 无法读取外部 DTD 'mybatis-3-config.dtd', 因为 accessExternalDTD 属性设置的限制导致不允许 'http' 访问。
at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:263)
at org.apache.ibatis.parsing.XPathParser.<init>(XPathParser.java:127)
at org.apache.ibatis.builder.xml.XMLConfigBuilder.<init>(XMLConfigBuilder.java:82)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:77)
... 2 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 49; 外部 DTD: 无法读取外部 DTD 'mybatis-3-config.dtd', 因为 accessExternalDTD 属性设置的限制导致不允许 'http' 访问。
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:204)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:178)
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)