在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/Java/ 打包后程序報(bào)錯(cuò):Type interface XXX is not known

打包后程序報(bào)錯(cuò):Type interface XXX is not known to the MapperRegistry.

1 問(wèn)題描述
框架使用springboot,項(xiàng)目在開發(fā)過(guò)程中可以在eclipse中正常測(cè)試。但是一旦使用打包后就會(huì)拋出Type interface XXX is not known to the MapperRegistry.此異常。
我已經(jīng)檢查過(guò)打包后的jar包,jar包中確實(shí)存在xml文件,也不存在namespace寫錯(cuò)的可能性。 mapper接口和xml文件也是在一個(gè)包中的。
我是使用的java配置,沒有使用xml配置文件。

2 相關(guān)代碼
clipboard.png

3 報(bào)錯(cuò)信息

Caused by: org.apache.ibatis.binding.BindingException: Type interface XXX is not known to the MapperRegistry.

4猜測(cè)的原因
我的mapper和xml文件是另外一個(gè)項(xiàng)目的jar文件中,是不是這個(gè)原因造成的呢?如果是怎么解決呢?

回答
編輯回答
命多硬

出錯(cuò)的原因

具體的原因是mybatis在通過(guò)mybatisConfig.addMappers方法掃描mapper和xml文件時(shí),不能夠掃描到嵌套的jar包中的文件。而我使用的是springboot打包成的可執(zhí)行jar包。所以才會(huì)出現(xiàn)此錯(cuò)誤。

解決方案

mybatis使用VFS執(zhí)行具體的掃描,可以將其實(shí)現(xiàn)替換成mybat/spring-boot-starter中的實(shí)現(xiàn)
clipboard.png

注意

你可能需要導(dǎo)入mybatis-springboot-starter

<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>1.3.1</version>
</dependency>

參考文檔
http://blog.csdn.net/cml_blog...

2017年2月8日 06:38