解决mybatis org.apache.ibatis.binding.BindingException异常

一 前言

1、项目采用maven进行编译打包 mybatis配置均完好,但出现配置文件未进入编译目录

2、本人不喜欢把mapper.xml单独放在resources,因为生成器生成xml文件指定位置,整整齐齐。看着舒服

报错信息如下

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.zyj.pluginstest.sys.dao.SysRoleDao.selectByExample

	at org.apache.ibatis.binding.MapperMethod$SqlCommand.(MapperMethod.java:227)
	at org.apache.ibatis.binding.MapperMethod.(MapperMethod.java:49)
	at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:65)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:58)
	at com.sun.proxy.$Proxy61.selectByExample(Unknown Source)
	at com.zyj.pluginstest.PluginsTestApplicationTests.contextLoads(PluginsTestApplicationTests.java:21)
	

二 问题分析

1、确认关键配置无误

(1)xml文件扫描路径

(2)dao接口扫描配置

解决mybatis org.apache.ibatis.binding.BindingException异常_第1张图片解决mybatis org.apache.ibatis.binding.BindingException异常_第2张图片

2 确认编译后文件

发现缺少xml文件

 解决mybatis org.apache.ibatis.binding.BindingException异常_第3张图片

解决mybatis org.apache.ibatis.binding.BindingException异常_第4张图片

上述归结与maven编译过程中会忽略非resources目录下的非java文件,
即不会将xml以及properties等文件打包进classes,所以需要手动在编译项目时加入。

三 解决方法

在pom.xml build标签内加入 resources配置,不过滤配置文件即可

  
		
		
			
                
				src/main/java
				
					**/*.properties
					**/*.xml
				
				false
			
		
	

重新编译,出现xml文件,运行正常 

解决mybatis org.apache.ibatis.binding.BindingException异常_第5张图片

你可能感兴趣的:(maven,mybatis)