org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.test.data.dao.SysFormFieldMapper.insertList
	at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:225) ~[mybatis-3.4.4.jar:3.4.4]
	at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:48) ~[mybatis-3.4.4.jar:3.4.4]
	at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:65) ~[mybatis-3.4.4.jar:3.4.4]
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:58) ~[mybatis-3.4.4.jar:3.4.4]
	at com.sun.proxy.$Proxy93.insertList(Unknown Source) ~[?:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_171]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_171]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_171]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333) ~[spring-aop-4.3.11.RELEASE.jar:4.3.11.RELEASE]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) ~[spring-aop-4.3.11.RELEASE.jar:4.3.11.RELEASE]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.3.11.RELEASE.jar:4.3.11.RELEASE]
	at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136) ~[spring-tx-4.3.11.RELEASE.jar:4.3.11.RELEASE]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.11.RELEASE.jar:4.3.11.RELEASE]
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) ~[spring-aop-4.3.11.RELEASE.jar:4.3.11.RELEASE]
	at com.sun.proxy.$Proxy94.insertList(Unknown Source) ~[?:?]

对于这个错,有以下几种可能:

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.test.data.dao.SysFormFieldMapper.insertList

1. mapper文件中有某个方法, xml中没有。

2. 未配置xml的扫描:只设置了mapper的bean路径,而没有设置xml的扫描路径,将这些配置信息没有设置给 SqlSessionFactoryBean,运行时无法找到xml namespace下的方法。

    private static final String MYBATIS_CONFIG = "mybatis_config.xml";
    private static final String MAPPER_PATH = "/com/realpower/data/mapper/*.xml";

    @Bean
    public SqlSessionFactoryBean createSqlSessionFactoryBean() throws IOException {
        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
        //设置mybatis configuration 扫描路径
        sqlSessionFactoryBean.setConfigLocation(new ClassPathResource(MYBATIS_CONFIG));
        //添加mapper 扫描路径
        PathMatchingResourcePatternResolver pathMatchingResourcePatternResolver = new PathMatchingResourcePatternResolver();
        String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + MAPPER_PATH;
        sqlSessionFactoryBean.setMapperLocations(pathMatchingResourcePatternResolver.getResources(packageSearchPath));
        //设置datasource
        sqlSessionFactoryBean.setDataSource(dataSource());
        return sqlSessionFactoryBean;
    }

3. xml文件未添加到项目的resources下:

       maven项目中,java路径下的是需要编译的,识别java文件,但xml不编译,所以在编译后的实际项目文件目录下,在java/mapper这个路径并没有生成xml文件。因为xml不可编译。而maven项目中的resources目录就是放置配置文件的,在项目编译后,xml文件正常存在。如果想在java路径下也能编译后生成xml,需要在pom文件中添加配置,把xml生成到java目录下。

(1)在pom中指定

 <build>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
        </resources>
</build>

(2)手动指定xml,添加到resources下

4. 也有可能Generator插件的问题,需要将Generator自动生成的mapper、xml、pojo,全部删除,再重新生成。

5. 也有可能是idea 编辑器的问题,重新清理IDE的缓存。

以上问题全部排查后, 删除target, 重新编译最新代码运行。其中红色的两条,本人已踩过坑。如还未解决,欢迎讨论!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值