在 myBatis 映射器文件中包含实体

发布于 2025-01-06 03:09:46 字数 964 浏览 1 评论 0原文

我正在从 iBatis 2.x 升级到 myBatis 3.0.6,并且我有一个映射器文件,其中包含外部实体,如下所示:

    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"
[
    <!ENTITY rating_analysis_state_cases SYSTEM "classpath://ibatis/includes/rating_analysis_state_cases.sql">
]>

在 iBatis 下,这曾经工作正常。

我所做的唯一结构更改是将 ibatis 文件夹更改为 mybatis。

然而,当我现在运行它时,我得到以下异常/堆栈跟踪:

Caused By: java.net.MalformedURLException: unknown protocol: classpath
    at java.net.URL.<init>(URL.java:574)
    at java.net.URL.<init>(URL.java:464)
    at java.net.URL.<init>(URL.java:413)
    at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:650)
    at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(XMLEntityManager.java:1315)

有没有人知道是否有我可能不知道的更改?

那么类路径不是一个已知的协议吗?如果没有,我可以使用什么协议以及如何使用?

I'm upgrading from iBatis 2.x to myBatis 3.0.6 and I have a mapper file which includes an external entity as follows:

    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"
[
    <!ENTITY rating_analysis_state_cases SYSTEM "classpath://ibatis/includes/rating_analysis_state_cases.sql">
]>

Under iBatis this used to work fine.

The only structural change I've made is that I changed the ibatis folder to mybatis.

However when I now run it I get the following exception/stacktrace:

Caused By: java.net.MalformedURLException: unknown protocol: classpath
    at java.net.URL.<init>(URL.java:574)
    at java.net.URL.<init>(URL.java:464)
    at java.net.URL.<init>(URL.java:413)
    at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:650)
    at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(XMLEntityManager.java:1315)

Has anyone got any idea as to whether something's changed that I might not know about?

Is classpath then not a known protocol? If not, what protocol could I use and how?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

╰◇生如夏花灿烂 2025-01-13 03:09:46

可能和MyBATIS没有关系。或者 Xerces,就此而言,因为类路径协议应该使用关注点分离原则在两个组件之外进行处理。我怀疑 iBATIS 是否注册了“classpath:”协议处理程序 - 在我的源代码中,没有 URLStreamHandler 实现。也许您的堆栈上的其他组件执行了此操作,并且您在切换到 myBatis 时将其删除。

本质上,从 Java 中的类路径加载资源的 url 为您提供答案。

您所需要做的就是添加一个扩展 URLStreamHandler 的小类并实现 URLStreamHandlerFactory。两者都非常简单,大约需要十几行代码。

您可以尝试查看以前的技术堆栈,如果有某个组件完成的 java.net.URLStreamHandler 实现(二进制文件中的全文搜索就可以解决问题,但是您需要看看是否它实际上是在实现“classpath:” - 上面的答案提供了详尽的见解)

It probably has nothing to do with MyBATIS. Or Xerces, for that matter, since classpath protocol should be handled outside of both components, using the separation of concern principle. I doubt iBATIS had "classpath:" protocol handler registered - in the source code I have, there is no URLStreamHandler implementation. Maybe some other component on your stack did it though, and you removed it when switching to myBatis.

Essentially, url to load resources from the classpath in Java has an answer for you.

All you need to do is to add a small class extending URLStreamHandler and implement a URLStreamHandlerFactory. Both are very simple and require around a dozen lines of code.

You can try looking in your previous technology stack, if there was a java.net.URLStreamHandler implementation done by some component (full text searching in binary files will do the trick, but then you need to see if it actually was implementing "classpath:" - the answer above provides exhaustive insight)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文