Error creating bean with name ‘datasource’ defined in class path resource

Use idea to create a new spring boot project, do nothing, create a new controller, and then start to report an error

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

 

Reason: spring boot will load by default org.springframework.boot . autoconfigure.jdbc.DataSourceAutoConfiguration class

Because there is no configuration information related to datasource in the new spring boot project, an error is reported as soon as it is started

Add the following to the application class:

@EnableAutoConfiguration(exclude={DataSou rceAutoConfiguration.class })

 

Or configure the datasource information and complete the configuration file

Read More: