Error creating bean with name ‘dataSource‘ defined in class path resource

异常信息

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [com/alibaba/druid/spring/boot/autoconfigure/DruidDataSourceAutoConfigure.class]: Invocation of init method failed; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
Error creating bean with name ‘dataSource‘ defined in class path resource_第1张图片

异常原因

该异常出现通常是因为项目中导入了持久层相关的依赖,但是配置文件中却又没有编写相关配置

解决办法

方法一. 编写持久层的相关配置

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/gulimall_pms?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useSSL=false
    driver-class-name: com.mysql.cj.jdbc.Driver
    username: root
    password: ${yourpassword}
    type: com.alibaba.druid.pool.DruidDataSource

方法二. 删除掉持久层依赖
如:
Error creating bean with name ‘dataSource‘ defined in class path resource_第2张图片

方法三. 在springboot启动类上配置不加载持久层相关bean
Error creating bean with name ‘dataSource‘ defined in class path resource_第3张图片

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, DruidDataSourceAutoConfigure.class})
@EnableDiscoveryClient
public class GulimallSearchApplication {

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

}

你可能感兴趣的:(java,spring,spring,boot)