[英]MyBatis mapper location
我在兩個模塊中的MyBatis配置有問題。 項目結構如下所示:
當我在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.