[英]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.