是否可以将 myBatis (iBatis) xml 映射器放在项目之外?
根据用户指南,我可以使用文件路径而不是 资源:
// 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您只需要在驱动器号前添加一个正斜杠即可。
You just need an additional forward slash before the drive letter.
Sql Map Config 会查找相对于类路径的映射文件,因此只需尝试将 ComponentMapper1.xml 添加到类路径的某个位置即可。
Sql Map Config looks for mapping files relatively to the classpath, so just try adding your ComponentMapper1.xml somewhere to the classpath.
如果您想在资源目录之外使用映射器,则必须使用
其中
file:///usr/local/ComponentMapper1.xml
是 XML 文件的路径,而不是资源。You must use
Where
file:///usr/local/ComponentMapper1.xml
is the path to your XML File, instead of the resource if you want use mappers outside resource dir.