簡體   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