我是靠谱客的博主 壮观鸡,最近开发中收集的这篇文章主要介绍MyBatis错误--Invalid bound statement (not found),觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

今天在开发项目的时候使用MyBatis发生错误:Invalid bound statement (not found)

具体错误信息:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobTaskServiceImpl': Invocation of init method failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.mkit.task.manager.dao.ScheduleJobMapper.getAll
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:136)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:408)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1566)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
View Code
Caused by: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.mkit.task.manager.dao.ScheduleJobMapper.getAll
    at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:189)
    at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:43)
    at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:58)
    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:51)
    at com.sun.proxy.$Proxy19.getAll(Unknown Source)
    at com.mkit.task.manager.service.impl.JobTaskServiceImpl.init(JobTaskServiceImpl.java:154)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:349)
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:300)
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:133)
    ... 61 more
View Code

 

通过分析找到了问题的原因。我出现这个错误的主要原因是因为dao层和Mapper.xml是从别的项目中copy过来的,然后这些属性值都没有做更改,所以报这样的错误。

 

解决:

1.首先查看spring-mybatis.xml文件中,对于dao层的class扫描路径是否正确。

2.检查Mapper.xml文件中namespace属性值是否正确

3.检查Mapper.xml文件中resultMap中type属性值是否正确

<mapper namespace="com.mkit.task.manager.dao.ScheduleJobMapper">
    <resultMap id="BaseResultMap" type="com.mkit.task.manager.pojo.ScheduleJob">
        <id column="job_id" property="jobId" jdbcType="BIGINT" />
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
        <result column="job_name" property="jobName" jdbcType="VARCHAR" />
        <result column="job_group" property="jobGroup" jdbcType="VARCHAR" />
        <result column="job_status" property="jobStatus" jdbcType="VARCHAR" />
        <result column="cron_expression" property="cronExpression"
            jdbcType="VARCHAR" />
        <result column="description" property="description" jdbcType="VARCHAR" />
        <result column="bean_class" property="beanClass" jdbcType="VARCHAR" />
        <result column="is_concurrent" property="isConcurrent"
            jdbcType="VARCHAR" />
        <result column="spring_id" property="springId" jdbcType="VARCHAR" />
        <result column="method_name" property="methodName" jdbcType="VARCHAR" />
    </resultMap>

 

转载于:https://www.cnblogs.com/0xcafedaddy/p/6171470.html

最后

以上就是壮观鸡为你收集整理的MyBatis错误--Invalid bound statement (not found)的全部内容,希望文章能够帮你解决MyBatis错误--Invalid bound statement (not found)所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(62)

评论列表共有 0 条评论

立即
投稿
返回
顶部