开发者社区> 问答> 正文

mysql自动实现dao类, 报错Exception in thread "ma?报错

Exception in thread "main" org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):

先贴配置:


<!-- myBatis 配置 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="configLocation" value="classpath:mybatis-config.xml"/>
        <property name="dataSource" ref="dataSource"/>
        <property name="mapperLocations" value="classpath*:com/haoyin/logic/dao/*.xml"/>
    </bean>

    <!-- 配置sqlSessionTemplate -->
    <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
        <constructor-arg index="0" ref="sqlSessionFactory" />
    </bean>

    <!-- mybatis自动实现dao-->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.haoyin.logic.dao"/>
    </bean>


网上说上面最后错误,我这里是指定对的, sqlSessionFactory里的mapperLocations也是对的.

Exception in thread "main" org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.haoyin.logic.dao.UserLoginDao.getTokenByUid
	at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:196)
	at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:44)
	at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:59)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
	at com.sun.proxy.$Proxy11.getTokenByUid(Unknown Source)
	at com.haoyin.logic.service.UserLoginServiceImpl.authenticate(UserLoginServiceImpl.java:20)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
	at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
	at com.sun.proxy.$Proxy15.authenticate(Unknown Source)
	at com.haoyin.logic.service.UserLoginServiceTest.main(UserLoginServiceTest.java:19)



从报错信息看, 我的mapper文件的namespace也是对的, 接口里的方法也是有的. 下面贴我接口的代码

import com.haoyin.logic.bean.UserLogin;
import org.apache.ibatis.annotations.Param;


/**
 * Created by dong on 2016/1/23.
 */
public interface UserLoginDao {

    String getTokenByUid(@Param("uid")String uid);

    String update(@Param("userLogin")UserLogin userLogin);

}



mapper文件:

<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.haoyin.logic.dao.UserLoginDao">

    <select id="getTokenByUid"  resultType="string">
        SELECT token FROM v1_userLogin WHERE uid = (#{uid})
    </select>

    
    <update id="update">
        UPDATE v1_userLogin
        <set>
            <if test="token != null">token = (#{token}),</if>
            <if test="expire != null">expire = (#(expire)),</if>
            <if test="lastAccessTimestamp != null">lastAccessTimestamp = (#(lastAccessTimestamp)) </if>
        </set>
        WHERE uid = (#{uid})
    </update>

</mapper>



找了俩小时了,搜了很多, 但是仍然没解决. 请大家帮忙看看


展开
收起
爱吃鱼的程序员 2020-06-10 14:39:42 738 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    <divclass='ref'><divclass='ref'>

    引用来自“JuSole”的评论

    没找到xml文件,看看路径对不?回复<aclass='referer'target='_blank'>@JuSole:按照你的方法,我的问题也解决了,太感谢你遇到的问题都是我走过的路。呵呵,慢慢来就行了。我流下来感动的泪水.太感谢了.真是这个原因.定位问题和搜索的能力仍需加强,感谢<property<spanstyle="font-family:Consolas,'BitstreamVeraSansMono','CourierNew',Courier,monospace;font-size:14px;line-height:15.390625px;background-color:#FFFFFF;">name="mapperLocations"<spanstyle="font-family:Consolas,'BitstreamVeraSansMono','CourierNew',Courier,monospace;font-size:14px;line-height:15.390625px;background-color:#FFFFFF;">value="classpath*:com/haoyin/logic/dao/ .xml"/>改为在<spanstyle="color:#0000FF;font-family:Consolas,'BitstreamVeraSansMono','CourierNew',Courier,monospace;font-size:14px;line-height:15.390625px;background-color:#FFFFFF;">mybatis-config.xml中清华手动的试试。如果在mybatis里手动加mapper的话.会告诉我找不到对应的xml文件。但是路径肯定是对的。我在想会不会是我分了模块的原因???没找到xml文件,看看路径对不?回复<aclass='referer'target='_blank'>@plugin:你确定这两个没问题呢,找不到mapper文件都是这两个造成的。回复<aclass='referer'target='_blank'>@JuSole:还是一样.似乎没有找到mapper文件回复<aclass='referer'target='_blank'>@plugin:1、如果用的mvn,那就检查xml复制过去了没。2、这么配置:<propertyname="mapperLocations"value="classpath:com/huaxin/**/*Mapper.xml"></property>路径肯定是对的。我在想会不会是我分了模块的原因呢<divclass='ref'>

    引用来自“JuSole”的评论

    没找到xml文件,看看路径对不?

    2020-06-10 14:39:57
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
搭建电商项目架构连接MySQL 立即下载
搭建4层电商项目架构,实战连接MySQL 立即下载
PolarDB MySQL引擎重磅功能及产品能力盛大发布 立即下载

相关镜像