zoukankan      html  css  js  c++  java
  • init datasource error / Error creating bean with name 'xxx' / Error creating bean with name 'dataSource' defined in class path /com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException

    [2019-12-26 10:06:58.959] boot - ERROR [main] ---  , url: jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull
    
    org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'helloWorldController': Unsatisfied dependency expressed through field 'orderRecordMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'orderRecordMapper' defined in file [D:ProjectJava Eclipse
    mqpdemo	argetclassescomexample
    mqpdemomapperOrderRecordMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionFactory' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [spring/spring-jdbc.xml]: Invocation of init method failed; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
    
    Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'orderRecordMapper' defined in file [D:ProjectJava Eclipse
    mqpdemo	argetclassescomexample
    mqpdemomapperOrderRecordMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionFactory' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [spring/spring-jdbc.xml]: Invocation of init method failed; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
    
    Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionFactory' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [spring/spring-jdbc.xml]: Invocation of init method failed; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
    
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [spring/spring-jdbc.xml]: Invocation of init method failed; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
    
    Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
    
    Caused by: java.lang.NullPointerException: null
    

    1. 修改mysql依赖驱动版本, 之前用的是5.x的版本

    <mysql.version>8.0.13</mysql.version>

    2. url的问题: 修改参数为characterEncoding=utf8&useUnicode=true&useSSL=false&serverTimezone=UTC(参考https://www.cnblogs.com/chenxi-mxj/p/11967850.html

     

    3. 检查druid配置中是否缺少driverClassName

    <property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>

    4. Mapper文件中添加@Mapper注解

    5. 启动类需要添加扫描注解

    @ImportResource(locations = "classpath:spring/spring-jdbc.xml")
    @MapperScan(basePackages = {"com.example.jay.mapper"})

  • 相关阅读:
    linux基础命令一
    Mac安装vue cli或者electron时 npm i 报错
    记MacOS抹盘后--使用U盘安装MacOS实录
    腾讯云申请SSL证书与Nginx配置Https
    Windows Server 2016 安装虚拟机版黑群晖
    FreeNas搭建踩坑指南(三)
    FreeNas搭建踩坑指南(二)
    FreeNas搭建踩坑指南(一)
    Apache2配置多域名站点及支持https
    ubuntu server 16.04 开启root密码登录
  • 原文地址:https://www.cnblogs.com/chenxi-mxj/p/12100664.html
Copyright © 2011-2022 走看看