是否可以将 myBatis (iBatis) xml 映射器放在项目之外?

发布于 2024-09-05 04:30:32 字数 813 浏览 3 评论 0原文

根据用户指南,我可以使用文件路径而不是 资源:


// Using classpath relative resources
<mappers>
    <mapper resource="org/mybatis/builder/AuthorMapper.xml"/>
</mappers>

// Using url fully qualified paths
<mappers>
    <mapper url="file:///var/sqlmaps/AuthorMapper.xml"/>
</mappers>

在我的项目中,我试图将我的映射器 xml 放在项目“外部” 我正在这样做:

<mapper url="file://D:/Mappers/ComponentMapper1.xml" /> 

我的 log4j 控制台的输出: <代码>

Error building SqlSession. 
The error may exist in file://D:/Mappers/ComponentMapper1.xml 
Cause: org.apache.ibatis.builder.BuilderException: Error parsing 
SQL Mapper Configuration. Cause: java.net.UnknownHostException: D 

Is it bug or it's me doing something wrong?

According to the user guide i am able to use file path instead of
resource:


// Using classpath relative resources
<mappers>
    <mapper resource="org/mybatis/builder/AuthorMapper.xml"/>
</mappers>

// Using url fully qualified paths
<mappers>
    <mapper url="file:///var/sqlmaps/AuthorMapper.xml"/>
</mappers>

in my project I'm trying to put my mapper xml "outside" the project
and i'm doing this:

<mapper url="file://D:/Mappers/ComponentMapper1.xml" /> 

The output of my log4j console:

Error building SqlSession. 
The error may exist in file://D:/Mappers/ComponentMapper1.xml 
Cause: org.apache.ibatis.builder.BuilderException: Error parsing 
SQL Mapper Configuration. Cause: java.net.UnknownHostException: D 



Is it bug or it's me doing something wrong?

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

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

发布评论

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

评论(3

落日海湾 2024-09-12 04:30:32

您只需要在驱动器号前添加一个正斜杠即可。

You just need an additional forward slash before the drive letter.

一身软味 2024-09-12 04:30:32

Sql Map Config 会查找相对于类路径的映射文件,因此只需尝试将 ComponentMapper1.xml 添加到类路径的某个位置即可。

set CLASSPATH=%CLASSPATH%;D:/Mappers/

...

<mapper resource="ComponentMapper1.xml" />

Sql Map Config looks for mapping files relatively to the classpath, so just try adding your ComponentMapper1.xml somewhere to the classpath.

set CLASSPATH=%CLASSPATH%;D:/Mappers/

...

<mapper resource="ComponentMapper1.xml" />
命比纸薄 2024-09-12 04:30:32

如果您想在资源目录之外使用映射器,则必须使用

<mapper url="file:///usr/local/ComponentMapper1.xml" />

其中 file:///usr/local/ComponentMapper1.xml 是 XML 文件的路径,而不是资源。

You must use

<mapper url="file:///usr/local/ComponentMapper1.xml" />

Where file:///usr/local/ComponentMapper1.xmlis the path to your XML File, instead of the resource if you want use mappers outside resource dir.

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