记录一次gradle依赖问题的解决思路:Failed to determine a suitable driver class

问题关键字

Failed to determine a suitable driver class

问题描述

报错信息如下:

2019-03-06 09:53:43.991|localhost-startStop-1|INFO |o.s.cloud.alibaba.sentinel.SentinelWebAutoConfiguration.servletRequestListener:73|[Sentinel Starter] register Sentinel with urlPatterns: [/*].
2019-03-06 09:53:44.723|localhost-startStop-1|INFO |o.s.boot.web.servlet.FilterRegistrationBean.log:87|Mapping filter: 'commonFilter' to urls: [/*]
2019-03-06 09:53:44.723|localhost-startStop-1|INFO |o.s.boot.web.servlet.FilterRegistrationBean.log:87|Mapping filter: 'characterEncodingFilter' to: [/*]
2019-03-06 09:53:44.723|localhost-startStop-1|INFO |o.s.boot.web.servlet.FilterRegistrationBean.log:87|Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2019-03-06 09:53:44.724|localhost-startStop-1|INFO |o.s.boot.web.servlet.FilterRegistrationBean.log:87|Mapping filter: 'httpPutFormContentFilter' to: [/*]
2019-03-06 09:53:44.724|localhost-startStop-1|INFO |o.s.boot.web.servlet.FilterRegistrationBean.log:87|Mapping filter: 'requestContextFilter' to: [/*]
2019-03-06 09:53:44.724|localhost-startStop-1|INFO |o.s.boot.web.servlet.FilterRegistrationBean.log:87|Mapping filter: 'cat-filter' to urls: [/*]
2019-03-06 09:53:44.724|localhost-startStop-1|INFO |o.s.boot.web.servlet.FilterRegistrationBean.log:87|Mapping filter: 'sentinelFilter' to urls: [/*]
2019-03-06 09:53:44.724|localhost-startStop-1|INFO |o.s.boot.web.servlet.FilterRegistrationBean.log:87|Mapping filter: 'httpCatCrossFliter' to urls: [/*]
2019-03-06 09:53:44.724|localhost-startStop-1|INFO |o.s.boot.web.servlet.FilterRegistrationBean.log:87|Mapping filter: 'corsInterceptor' to: [/*]
2019-03-06 09:53:44.725|localhost-startStop-1|INFO |o.s.boot.web.servlet.ServletRegistrationBean.log:87|Servlet dispatcherServlet mapped to [/]
2019-03-06 09:53:44.795|restartedMain|INFO |org.springframework.aop.framework.CglibAopProxy.log:87|Method [void com.zaxxer.hikari.HikariConfig.seal()] is package-visible across different ClassLoaders and cannot get proxied via CGLIB: Declare this method as public or protected if you need to support invocations through the proxy.
2019-03-06 09:53:44.956|restartedMain|WARN |o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext.log:87|Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Unsatisfied dependency expressed through method 'entityManagerFactory' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'entityManagerFactoryBuilder' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Unsatisfied dependency expressed through method 'entityManagerFactoryBuilder' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaVendorAdapter' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.JpaVendorAdapter]: Factory method 'jpaVendorAdapter' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.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-03-06 09:53:44.961|restartedMain|WARN |o.s.beans.factory.support.DisposableBeanAdapter.log:87|Invocation of destroy method failed on bean with name 'inMemoryDatabaseShutdownExecutor': org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
2019-03-06 09:53:44.997|restartedMain|INFO |org.apache.catalina.core.StandardService.log:180|Stopping service [Tomcat]
2019-03-06 09:53:45.024|localhost-startStop-1|WARN |org.apache.catalina.loader.WebappClassLoaderBase.log:180|The web application [api] appears to have started a thread named [sentinel-datasource-auto-refresh-task-thread-1] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 sun.misc.Unsafe.park(Native Method)
 java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
 java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
 java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1093)
 java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)
 java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
 java.lang.Thread.run(Thread.java:748)
2019-03-06 09:53:45.025|localhost-startStop-1|WARN |org.apache.catalina.loader.WebappClassLoaderBase.log:180|The web application [api] appears to have started a thread named [sentinel-metrics-record-task-thread-1] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 sun.misc.Unsafe.park(Native Method)
 java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
 java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
 java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1093)
 java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)
 java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
 java.lang.Thread.run(Thread.java:748)
Disconnected from the target VM, address: '127.0.0.1:59182', transport: 'socket'

Process finished with exit code 1

思考起因

添加了一个依赖之后

排查原因

查看这个依赖是否依赖了别的其他依赖,
查找之后确实如此;

解决方案

排除依赖

    compile 'com.xxx.cloud:xxx-client:0.0.1-SNAPSHOT' , {
        exclude(module: 'spring-boot-starter-data-jpa')
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 这个错误是由于Spring Boot应用程序没有找到合适的JDBC驱动程序引起的。通常情况下,这种错误是由以下原因引起的: 1. 数据库驱动程序未正确配置或未在类路径中。请确保在您的应用程序的pom.xml或gradle.build文件中添加正确的JDBC驱动程序依赖。 2. 数据库URL格式不正确。请确保数据库连接URL的格式正确,并且与您的数据库配置相匹配。 3. 应用程序配置文件中的属性名称拼写错误或格式不正确。请检查您的应用程序配置文件中的属性名称是否正确,并确保所有属性值都按照正确的格式进行设置。 4. 数据库服务器连接不可用。请确保您的数据库服务器正在运行,并且网络连接可用。 如果您能提供更多上下文信息,我可以给您更具体的建议。 ### 回答2: 这个错误表示在 Spring Boot 应用程序启动过程中尝试创建数据源时出现了问题。具体来说,Spring Boot 无法确定适合该数据源的驱动程序类。 通常,这个错误的原因有两种可能性: 1. 数据库驱动程序未正确配置 Spring Boot 需要知道用于连接数据库的驱动程序。这通常通过在应用程序的配置文件(如 application.properties 或 application.yml)中设置 spring.datasource.driver-class-name 属性来实现。如果该属性未正确设置或未设置,则会引发此错误。 要解决问题,请确保在 Spring Boot 应用程序的配置文件中正确设置了驱动程序名称。 2. 驱动程序未包含在应用程序中 如果驱动程序未包含在应用程序的类路径中,则无法加载它。这可能是因为尚未将数据库驱动程序添加到项目依赖项中,或者依赖项中的版本不适用于当前的数据库或应用程序。 要解决问题,请确保以下几点: - 检查应用程序的依赖项以确保包含了正确版本的数据库驱动程序。 - 确认驱动程序的 JAR 文件包含在应用程序的类路径中,例如,可以通过将驱动程序的 JAR 文件添加到应用程序的 lib 目录或将其包含在构建中来实现。 最后,如果以上解决方法都没有解决问题,则可以查看异常堆栈跟踪以获取更多信息,以便找到导致此问题的根本原因。 ### 回答3: 这个问题是由于Spring Boot自动配置无法确定适合的数据库驱动程序引起的。在Spring Boot中,我们可以使用自动配置来为我们的应用程序配置数据源,以便我们可以很容易地连接到数据库。 但是,当使用自动配置时,如果没有在应用程序的类路径中找到适合的数据库驱动程序,就会出现这种情况。这意味着我们需要手动添加数据库驱动程序依赖项。 解决问题的步骤如下: 1. 确保数据库驱动程序依赖项已添加到应用程序的pom.xml文件或gradle.build文件中。 2. 如果使用嵌入式数据库(例如H2),请确保正确地配置了其依赖项。 3. 检查应用程序的application.properties或application.yml文件中的数据库连接配置是否正确。特别注意数据库驱动程序的类名是否正确。 4. 如果仍然存在问题,请检查数据库驱动程序的版本是否与应用程序兼容。如果使用过时的驱动程序,可能会导致错误。 总之,Spring Boot自动配置非常强大,可以简化应用程序的配置过程。但是,在使用自动配置时,我们需要确保所有必需的依赖项已添加,并正确地配置了应用程序的数据库连接。如果遇到问题,我们应该仔细检查配置并查找可用的解决方案。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值