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"})

  • 相关阅读:
    rabbitmq channel参数详解
    rabbitmq direct、fanout、topic 三种Exchange java 代码比较
    spark 性能优化
    spark sql 窗口函数over partition by
    Python爬虫从入门到进阶(4)之xpath的使用
    Python爬虫从入门到进阶(3)之requests的使用
    Python爬虫从入门到进阶(2)之urllib库的使用
    Mac环境下Redis的安装
    Mac环境下Vagrant的安装
    Mac环境下Scrapy的安装
  • 原文地址:https://www.cnblogs.com/chenxi-mxj/p/12100664.html
Copyright © 2011-2022 走看看