yuyanjun340
yuyanjun340
采纳率0%
2017-03-09 01:04

mybatis整合spring框架 调试报错

type Exception report

message Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:

Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user 'root'@'localhost' (using password: YES))

The error may exist in cn/itcast/ssm/mapper/ItemsMapperCustom.xml

The error may involve cn.itcast.ssm.mapper.ItemsMapperCustom.findItemsList

The error occurred while executing a query

Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user 'root'@'localhost' (using password: YES))

org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:927)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:811)
javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796)
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)
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

14条回答

  • yuyanjun340 yuyanjun340 4年前

    jdbc都正确的 密码和正确的就是访问报错

    点赞 评论 复制链接分享
  • engchina engchina 4年前

    看这个错误信息。数据库连接没连上。
    你的root密码错误,或者root不能通过localhost连接。
    》Access denied for user 'root'@'localhost' (using password: YES)

    点赞 评论 复制链接分享
  • yuyanjun340 yuyanjun340 4年前

    ItemsMapperCustom.xml
    <?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" >

    <!-- 定义商品查询的sql片段,就是商品查询条件 -->

    <!-- 使用动态sql,通过if判断,满足条件进行sql拼接 -->
    <!-- 商品查询条件通过ItemsQueryVo包装对象 中itemsCustom属性传递 -->


    items.name LIKE '%${itemsCustom.name}%'

    <!-- 商品列表查询 -->
    <!-- parameterType传入包装对象(包装了查询条件)
        resultType建议使用扩展对象
     -->
    <select id="findItemsList" parameterType="cn.itcast.ssm.po.ItemsQueryVo"
         resultType="cn.itcast.ssm.po.ItemsCustom">
        SELECT items.* FROM items  
        <where>
            <include refid="query_items_where"></include>
        </where>
    </select>
    

    点赞 评论 复制链接分享
  • yuyanjun340 yuyanjun340 4年前

    图片说明

    点赞 评论 复制链接分享
  • yuyanjun340 yuyanjun340 4年前

    ItemsMapperCustom.java
    package cn.itcast.ssm.mapper;

    import cn.itcast.ssm.po.Items;
    import cn.itcast.ssm.po.ItemsCustom;
    import cn.itcast.ssm.po.ItemsExample;
    import cn.itcast.ssm.po.ItemsQueryVo;

    import java.util.List;
    import org.apache.ibatis.annotations.Param;

    public interface ItemsMapperCustom {
    //商品查询列表
    public List findItemsList(ItemsQueryVo itemsQueryVo)throws Exception;

    点赞 评论 复制链接分享
  • yuyanjun340 yuyanjun340 4年前

    <!-- 定义商品查询的sql片段,就是商品查询条件 -->

    <!-- 使用动态sql,通过if判断,满足条件进行sql拼接 -->
    <!-- 商品查询条件通过ItemsQueryVo包装对象 中itemsCustom属性传递 -->


    items.name LIKE '%${itemsCustom.name}%'

    <!-- 商品列表查询 -->
    <!-- parameterType传入包装对象(包装了查询条件)
        resultType建议使用扩展对象
     -->
    <select id="findItemsList" parameterType="cn.itcast.ssm.po.ItemsQueryVo"
         resultType="cn.itcast.ssm.po.ItemsCustom">
        SELECT items.* FROM items  
        <where>
            <include refid="query_items_where"></include>
        </where>
    </select>
    

    点赞 评论 复制链接分享
  • sy7571871 syhleo 4年前

    还有,要确保mysql服务已经开启,和jdbc驱动包正确

    点赞 评论 复制链接分享
  • sy7571871 syhleo 4年前

    看一下,这里面findItemsList有没有错误!

    点赞 评论 复制链接分享
  • yuyanjun340 yuyanjun340 4年前

    org.apache.ibatis.exceptions.PersistenceException:

    Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user 'root'@'localhost' (using password: YES))

    The error may exist in cn/itcast/ssm/mapper/ItemsMapperCustom.xml

    The error may involve cn.itcast.ssm.mapper.ItemsMapperCustom.findItemsList

    The error occurred while executing a query

    Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user 'root'@'localhost' (using password: YES))

    org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:26)
    org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:111)
    org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:102)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    java.lang.reflect.Method.invoke(Unknown Source)
    org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358)
    com.sun.proxy.$Proxy6.selectList(Unknown Source)
    org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:198)
    org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:119)
    org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:63)
    org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
    com.sun.proxy.$Proxy7.findItemsList(Unknown Source)
    cn.itcast.ssm.service.impl.ItemsServiceImpl.findItemsList(ItemsServiceImpl.java:36)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    java.lang.reflect.Method.invoke(Unknown Source)
    org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
    org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    com.sun.proxy.$Proxy10.findItemsList(Unknown Source)
    cn.itcast.ssm.controller.ItemsController.queryItems(ItemsController.java:51)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    java.lang.reflect.Method.invoke(Unknown Source)
    org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
    org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
    org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:746)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:687)
    org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:915)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:811)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796)
    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

    点赞 评论 复制链接分享
  • yuyanjun340 yuyanjun340 4年前

    jdbc.driver=com.mysql.jdbc.Driver
    jdbc.url=jdbc:mysql://localhost:3306/mybatis
    jdbc.username=root
    jdbc.password=root

    点赞 评论 复制链接分享
  • yuyanjun340 yuyanjun340 4年前

    用户名密码没有错误啊

    点赞 评论 复制链接分享
  • lrx2011 podd 4年前

    CannotGetJdbcConnectionException: Could not get JDBC Connection;

    点赞 评论 复制链接分享
  • HackAge4619 写给初学者的几封信 4年前

    先改最明显的错误,连接数据库的用户名或密码错误!

    点赞 评论 复制链接分享
  • yuyanjun340 yuyanjun340 4年前

    数据库配置xml如下:
    <!-- 加载db.properties文件中的内容,db.properties文件中key命名要有一定的特殊规则 -->

    <!-- 配置数据源 ,dbcp -->

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <property name="driverClassName" value="${jdbc.driver}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
        <property name="maxActive" value="10" />
        <property name="maxIdle" value="5" />
    </bean>
    <!-- sqlSessionFactory -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!-- 数据库连接池 -->
        <property name="dataSource" ref="dataSource" />
        <!-- 加载mybatis的全局配置文件 -->
        <property name="configLocation" value="classpath:mybatis/sqlMapConfig.xml" />
    </bean>
    
    点赞 评论 复制链接分享

相关推荐