问题描述
- spring和mybatis集成时总报错 麻烦帮忙看下什么原因
- 项目请求数据的时候报
Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.business.dao.system.AdminMapper.selectByPrimaryKey
麻烦大神帮忙看下这是啥原因,找了好久不知道哪里弄错了spring-mybatis.xml文件配置
<bean id=""sqlSessionFactory"" class=""org.mybatis.spring.SqlSessionFactoryBean""> <property name=""dataSource"" ref=""dataSource"" /> <!-- 自动扫描entity目录 省掉Configuration.xml里的手工配置 --> <property name=""mapperLocations"" value=""*Mapper.xml"" /></bean>
AdminMapper.java的内容
package com.business.dao.system;
import com.business.models.system.Admin;
import org.springframework.stereotype.Repository;@Repository(value=""adminMapper"")
public interface AdminMapper {
int deleteByPrimaryKey(Long adminOid);int insert(Admin record);int insertSelective(Admin record);Admin selectByPrimaryKey(Long adminOid);int updateByPrimaryKeySelective(Admin record);int updateByPrimaryKey(Admin record);
}
AdminMapper.xm的内容
<?xml version=""1.0"" encoding=""UTF-8"" ?><!DOCTYPE mapper PUBLIC ""-//mybatis.org//DTD Mapper 3.0//EN"" ""http://mybatis.org/dtd/mybatis-3-mapper.dtd"" ><mapper namespace=""com.business.dao.system.AdminMapper"" > <resultMap id=""BaseResultMap"" type=""com.business.models.system.Admin"" > <id column=""admin_oid"" property=""adminOid"" jdbcType=""BIGINT"" /> <result column=""user_name"" property=""userName"" jdbcType=""VARCHAR"" /> <result column=""password"" property=""password"" jdbcType=""VARCHAR"" /> </resultMap> <sql id=""Base_Column_List"" > admin_oid user_name password </sql> <select id=""selectByPrimaryKey"" resultMap=""BaseResultMap"" parameterType=""java.lang.Long"" > select <include refid=""Base_Column_List"" /> from admin where admin_oid = #{adminOidjdbcType=BIGINT} </select> <delete id=""deleteByPrimaryKey"" parameterType=""java.lang.Long"" > delete from admin where admin_oid = #{adminOidjdbcType=BIGINT} </delete> <insert id=""insert"" parameterType=""com.business.models.system.Admin"" > insert into admin (admin_oid user_name password ) values (#{adminOidjdbcType=BIGINT} #{userNamejdbcType=VARCHAR} #{passwordjdbcType=VARCHAR} ) </insert> <insert id=""insertSelective"" parameterType=""com.business.models.system.Admin"" > insert into admin <trim prefix=""("" suffix="")"" suffixOverrides="" > <if test=""adminOid != null"" > admin_oid </if> <if test=""userName != null"" > user_name </if> <if test=""password != null"" > password </if> </trim> <trim prefix=""values ("" suffix="")"" suffixOverrides="" > <if test=""adminOid != null"" > #{adminOidjdbcType=BIGINT} </if> <if test=""userName != null"" > #{userNamejdbcType=VARCHAR} </if> <if test=""password != null"" > #{passwordjdbcType=VARCHAR} </if> </trim> </insert> <update id=""updateByPrimaryKeySelective"" parameterType=""com.business.models.system.Admin"" > update admin <set > <if test=""userName != null"" > user_name = #{userNamejdbcType=VARCHAR} </if> <if test=""password != null"" > password = #{passwordjdbcType=VARCHAR} </if> </set> where admin_oid = #{adminOidjdbcType=BIGINT} </update> <update id=""updateByPrimaryKey"" parameterType=""com.business.models.system.Admin"" > update admin set user_name = #{userNamejdbcType=VARCHAR} password = #{passwordjdbcType=VARCHAR} where admin_oid = #{adminOidjdbcType=BIGINT} </update></mapper>
现在启动时没有问题 但是一访问请求数据的时候就报错
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.business.dao.system.AdminMapper.selectByPrimaryKey
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)root cause
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.business.dao.system.AdminMapper.selectByPrimaryKey
org.apache.ibatis.binding.MapperMethod$SqlCommand.(MapperMethod.java:189)
org.apache.ibatis.binding.MapperMethod.(MapperMethod.java:43)
org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:58)
org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:51)
com.sun.proxy.$Proxy12.selectByPrimaryKey(Unknown Source)
com.business.service.system.Impl.SystemServiceImpl.findAdminByAdminOid(SystemServiceImpl.java:21)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
com.sun.proxy.$Proxy15.findAdminByAdminOid(Unknown Source)
controller.system.SystemController.findAdmin(SystemController.java:27)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:177)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:446)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:434)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
解决方案
@Repository(value=""adminMapper"")这里这样写感觉有问题啊,
看看我写的http://blog.csdn.net/evankaka/article/details/48785513
解决方案二:
我把@Repository(value=""adminMapper"")还是一样的 我这个mybatis的model mapper.java mapper.xml是用generator自动生成的,可是一直报那个错误,
怎么弄都不行。。。。。
解决方案三:
mapper.xml中的selectByPrimaryKey方法有问题!
解决方案四:
接口的定义没有和对应的xml文件对应,检查配置。