Spring Boot 启动报错Error creating bean with name 'dataSource' defined in class path resource

使用idea 新建了一个spring boot项目,什么都不干,新建一个controller,然后启动报错:

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

Spring Boot 启动报错Error creating bean with name 'dataSource' defined in class path resource_第1张图片

 

原因:spring boot会默认加载org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration类

因为新建的spring boot 工程中没有dataSource相关的配置信息,所以一启动就报错

在Application类上加上如下:

@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})

 

或者配置datasource信息,补全配置文件即可

你可能感兴趣的:(JavaWeb,SpringBoot)