SpringBoot startup error Failed to determine a suitable driver class

Add a simple controller to a new SpringBoot project from SpringBoot Initializer , and the startup error is as follows:

  . ____ _ __ _ _
 /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
(()\___ |'_ |'_| |'_ \/ _` | \ \ \ \
 \\/ ___)| |_)| | | | | || (_| |))))
  '|____| .__|_| |_|_| |_\__, | / / / /
 ==========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.8.RELEASE)

2019-09-09 10:37:16.750  INFO 11232 --- [           main] com.dongdong.demo.DemoApplication        : Starting DemoApplication on PC-20170304VFOZ with PID 11232 (E:\Spring\Projects\demo\target\classes started by Administrator in E:\Spring\Projects\demo)
2019-09-09 10:37:16.752  INFO 11232 --- [           main] com.dongdong.demo.DemoApplication        : No active profile set, falling back to default profiles: default
2019-09-09 10:37:17.711  INFO 11232 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-09-09 10:37:17.730  INFO 11232 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 16ms. Found 0 repository interfaces.
2019-09-09 10:37:18.023  INFO 11232 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$3d0e1f1a] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-09-09 10:37:18.327  INFO 11232 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2019-09-09 10:37:18.359  INFO 11232 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-09-09 10:37:18.360  INFO 11232 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.24]
2019-09-09 10:37:18.476  INFO 11232 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-09-09 10:37:18.476  INFO 11232 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1645 ms
2019-09-09 10:37:18.732  INFO 11232 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2019-09-09 10:37:18.842  WARN 11232 --- [           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
2019-09-09 10:37:18.843  INFO 11232 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'
2019-09-09 10:37:18.846  INFO 11232 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2019-09-09 10:37:18.860  INFO 11232 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-09-09 10:37:18.864 ERROR 11232 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class


Action:

Consider the following:
    If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
    If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).


Process finished with exit code 1

 

the reason

The application does not use DataSource, but introduces mybatis-spring-boot-starter in pom.xml

 

Problem solution

There are two types:
remove the dependency of mybatis-spring-boot-starter, so that it will not trigger the spring boot related
code    disable the spring boot automatically initialize the DataSource related code

There are two ways to prohibit:

In the @SpringBootApplication of the startup class, add

@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class,DataSourceTransactionManagerAutoConfiguration.class })

 

Configure in application.properties:

spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration

 

Get it done!

Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *