SpringBoot啓動報錯Failed to determine a suitable driver class

SpringBoot Initializer 新建SpringBoot項目添加一個簡單控制器,啓動報錯以下:web

 . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| | ) ) ) ) '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/ :: 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

 

 

 

緣由

應用沒有使用到DataSource,可是在pom.xml裏引入了mybatis-spring-boot-starterspring

 

問題解決辦法apache


有兩種:
  把mybatis-spring-boot-starter的依賴去掉,這樣就不會觸發spring boot相關的代碼
  把spring boot自動初始化DataSource相關的代碼禁止掉tomcat

禁止的辦法有兩種:mybatis

在啓動類的@SpringBootApplication加上app

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

 

在application.properties裏配置:ide

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

 

搞定!spring-boot

相關文章
相關標籤/搜索