我正在尝试在构建于docker本地模式的Quarkus项目中使用mybatis。加载xml映射文件时,会引发以下错误:
org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 108; External DTD: Failed to read external DTD 'mybatis-3 -mapper.dtd', because 'http' access is not allowed due to restriction set by the accessExternalDTD property.
at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:263)
at org.apache.ibatis.parsing.XPathParser.(XPathParser.java:127)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.(XMLMapperBuilder.java:81)我用来加载映射文件的代码片段是:
Configuration configuration = new Configuration();
String mapperResourceName = "mybatis/test.xml";
InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(mapperResourceName);
XMLMapperBuilder mapperParser = new XMLMapperBuilder(inputStream, configuration, mapperResourceName,
configuration.getSqlFragments());
mapperParser.parse();
MappedStatement mappedStatement = configuration.getMappedStatement("test");
BoundSql boundSql = mappedStatement.getBoundSql(params);而映射器文件是:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="Test">
<select id="test" >
SELECT t
FROM Test t
</select>
</mapper>我已经尝试添加了
<quarkus.native.additional-build-args>-J-Djavax.xml.accessExternalDTD=all</quarkus.native.additional-build-args>没有成功。
发布于 2021-05-01 01:52:52
我已经找到了解决问题的方法:在Dockerfile.native文件中,必须在应用程序启动时添加-Djavax.xml.accessExternalDTD=all。
您可以在https://github.com/draccagni/quarkus-hibernate-orm-mybatis-3上找到re项目
https://stackoverflow.com/questions/67323683
复制相似问题