繁体   English   中英

MyBatis映射器位置

[英]MyBatis mapper location

我在两个模块中的MyBatis配置有问题。 项目结构如下所示:

  • D B
    • src
      • 主要
        • 爪哇
          • VideosDAO.class
          • ConnectionFactory.class
          • Videos.class
          • VideosMapper.class
        • 资源
          • VideoMapper.xml
          • config.xml
    • pom.xml
  • 混合的
    • src
      • 主要
        • 爪哇
          • 文章类
          • Articles.class
          • ArticlesMapper.class
        • 资源
          • ArticlesMapper.xml
    • pom.xml

当我在DB模块中拥有所有东西时,我可以连接到数据库并执行SQL,但是当我想在MIXED模块中使用DB模块中的ConnectionFactory.class和config.xml时,它将无法正常工作。

### Error building SqlSession.
### Cause: org.apache.ibatis.builder.BuilderException: Error creating document 
instance.  Cause: org.xml.sax.SAXParseException; lineNumber: 24; columnNumber: 
24; Premature end of file.

我认为问题出在config.xml文件中

<mappers>
</mappers>

我已经尝试了以下所有方法: http : //www.mybatis.org/mybatis-3/configuration.html#mappers但没有任何效果:(任何关于config.xml应该如何允许我使用其他模块类的想法而不是复制它们,但同时使用其他模块中的映射器?

我的一些尝试:

 <mappers>
    <mapper url="file:///MIXED/src/main/resources/ArticlesMapper.xml"/>
    <mapper resource="VideoMapper.xml"/>
 </mappers>

<mappers>
    <mapper resource="MIXED/src/main/resources/ArticlesMapper.xml"/>
    <mapper resource="VideoMapper.xml"/>
</mappers>

首先,确保您的Maven MIXED模块依赖于Maven DB模块。 您需要这样做,以便可以使用类和资源。 将依赖项添加到MIXED模块的pom.xml中(例如查看此问题

完成此操作后, DB模块的类和资源位于MIXED模块的类路径中,您可以在config.xml引用它们,就像引用来自模块本身的资源一样:

<mappers>
   <mapper resource="VideoMapper.xml"/>
</mappers>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM