• springboot报错Error creating bean with name 'dataSource' defined in class path resource


    报错信息如下:

    2020-04-02 15:25:15.549 WARN 4360 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
    2020-04-02 15:25:15.549 INFO 4360 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
    2020-04-02 15:25:15.554 INFO 4360 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
    解决方法一:

    在启动类上加上@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})

    package com.example.securitycore;

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;

    @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
    @SpringBootApplication
    public class SecurityCoreApplication {

    public static void main(String[] args) {
    SpringApplication.run(SecurityCoreApplication.class, args);
    }

    }
    方法二

    在application.properties在添加配置

    spring.datasource.driver-class-name=com.mysql.jdbc.Driver
    spring.datasource.url=jdbc:mysql://localhost:3306/security_demo?characterEncoding=utf-8
    spring.datasource.data-username=root
    spring.datasource.data-password=root
    ————————————————
    版权声明:本文为CSDN博主「爱笑的女孩运气不会太差」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/qq_33439525/article/details/105271088

  • 相关阅读:
    PL/SQL中判断字段为空
    ArrayList知识详解
    那些碰到过的异常
    Java中的==和equals( )方法
    String,StringBuilder和StringBuffer
    树莓派3b+_32位linux系统arm架构安装JDK
    [杂]右键拷贝文件路径
    [023]模板成员函数为什么不能是虚函数
    [杂]几个好玩的网址
    [022]c++虚函数、多态性与虚表
  • 原文地址:https://www.cnblogs.com/telwanggs/p/14794389.html
Copyright © 2020-2023  润新知