栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

mybatis使用详解(mybatis not in)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

mybatis使用详解(mybatis not in)

Mybatis错误笔记:

1、org.apache.ibatis.binding.BindingException: Type interface com.ljh.dao.user.UserDao is not known to the MapperRegistry.

错误:解决办法: 2、java.lang.ExceptionInInitializerError .....Caused by:org.apache.ibatis.exceptions.PersistenceException:

错误:解决办法: 3 !!!**重中之重**,改完pom.xml记得刷新maven

1、org.apache.ibatis.binding.BindingException: Type interface com.ljh.dao.user.UserDao is not known to the MapperRegistry. 错误:
org.apache.ibatis.binding.BindingException: Type interface com.ljh.dao.user.UserDao is not known to the MapperRegistry.

	at org.apache.ibatis.binding.MapperRegistry.getMapper(MapperRegistry.java:47)
	at org.apache.ibatis.session.Configuration.getMapper(Configuration.java:868)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.getMapper(DefaultSqlSession.java:288)
	at com.ljh.dao.UserDaoTest.test1(UserDaoTest.java:17)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	---------------------------------------------略---------------------------------------

报这个错误很大可能是因为在MyBatis的主配置文件中,没有注册自己写的xml文件。
如:我的错误就是UserDao(UserMapper)接口对应的UserDaoImpl.xml配置文件,没有在主配置文件中进行注册。

解决办法:

找到自己Mybatis的主配置文件,在中进行xml文件注册







	
	
    
    
    
		
		
    

2、java.lang.ExceptionInInitializerError …Caused by:org.apache.ibatis.exceptions.PersistenceException: 错误:

本以为上面在主配置文件中注册完就好了,结果还有问题:

java.lang.ExceptionInInitializerError
	at com.ljh.dao.UserDaoTest.test1(UserDaoTest.java:15)<22:internal lines>
	```省略```22行
Caused by: org.apache.ibatis.exceptions.PersistenceException: 
### Error building SqlSession.
### The error may exist in com/ljh/dao/user/UserMapper.xml

他说我刚刚注册的这个地址上,没找到对应的UserMapper.xml文件,
那么如果你报错跟我一样,很可能是用maven构建了一个Web项目,用mybatis框架,但是自己写的xml文档,没有在resources目录下。
因为项目代码写完运行的时候,它会先把maven项目导出到一个target文件中,而导出的时候,一些非java文件的资源文件会被过滤掉,所以得配置一下你maven项目的pom.xml文件。让他不过滤你想用的一些资源文件(包括xml,properties,png等等等)

解决办法: 3 !!!重中之重,改完pom.xml记得刷新maven

找到当前maven项目的pom.xml文件,将 部分添加的配置中。
当然,在导出为可运行的项目时,你想不过滤掉哪些项目,就在中添加以哪些属性名结尾的文件。
重中之重,改完pom.xml记得刷新maven




    
        
            
            	
            	
                src/main/resources
                
                    ***.xml
                    
                    



我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号