【问题标题】:Spring boot application - Tomcat deployment - Failed to determine a suitable driver classSpring Boot 应用程序 - Tomcat 部署 - 无法确定合适的驱动程序类
【发布时间】:2020-01-14 09:02:46
【问题描述】:

从 IDE 运行时一切正常

尝试在 tomcat 服务器中部署应用程序时出现以下错误。

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is 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

Application.java

@SpringBootApplication
public class Application extends SpringBootServletInitializer {

  @Override
  protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    return application.sources(Application.class);
  }

  public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
  }
}

build.gradle

plugins {
    id 'java'
}

sourceCompatibility = 1.8

apply plugin: 'java'
apply plugin: 'war'

repositories {
    mavenCentral()
    maven { url "http://dayrhebfmi001.enterprisenet.org:8081/artifactory/libs-snapshot"}
}

dependencies {
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.1.7.RELEASE'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '2.1.7.RELEASE'
    compile group: 'org.postgresql', name: 'postgresql', version: '42.2.6'
    compile group: 'org.projectlombok', name: 'lombok', version: '1.18.8'
    annotationProcessor group: 'org.projectlombok', name: 'lombok', version: '1.18.8'
    compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.9'
    compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.28'
    testCompile group: 'junit', name: 'junit', version: '4.12'
    providedRuntime group: 'org.springframework.boot', name: 'spring-boot-starter-tomcat', version: '2.1.8.RELEASE'

}

application.properties

spring.datasource.platform=xxxxx
spring.datasource.url=xxxxx
spring.datasource.username=xxxxx
spring.datasource.password=xxxxx
spring.jpa.show-sql=true
spring.datasource.driver-class-name=org.postgresql.Driver

【问题讨论】:

  • 向我们展示您的 application.properties 文件。
  • 你应该添加参数 spring.datasource.driver-class-name=
  • 比如你使用的是postgresql:spring.datasource.driver-class-name=org.postgresql.Driver
  • 驱动程序名称来自 JDBC url。这意味着 URL 错误,或者驱动程序未正确包含在工件中。 spring.datasource.platform 不是二手资产。还要停止混合 Spring Boot 的版本,您包含来自 2.1.7 和 2.1.8 的 jar,这会在某处导致错误。接下来,您还应该使用 Spring Boot 插件来创建适当的战争。
  • @MychellTeixeira:添加了驱动程序名称,但仍然收到错误“无法实例化 [com.zaxxer.hikari.HikariDataSource]:无法确定合适的驱动程序类”

标签: java spring hibernate spring-boot tomcat


【解决方案1】:

您应该将驱动程序类配置添加到 application.properties:

spring.datasource.driver-class-name=org.postgresql.Driver

【讨论】:

    【解决方案2】:

    无法实例化 [com.zaxxer.hikari.HikariDataSource]:工厂方法“dataSource”抛出异常;嵌套异常是 org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: 无法确定合适的驱动类

    您的属性有几处看起来可疑。但我认为您可以通过按要求为其提供类名来解决此特定错误。

    spring.datasource.driver-class-name=oracle.jdbc.OracleDriver

    (或您正在使用的任何数据库)

    加分加分

    spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
    

    (再次,或您正在使用的任何数据库)

    编辑: 当然,除非您已将数据库驱动程序 jar 文件放入 tomcat/lib 中,否则您需要将其添加到您的依赖项中,以便将其捆绑到 war 文件中。

    【讨论】:

    • 添加了驱动类名,但仍然收到错误“无法实例化 [com.zaxxer.hikari.HikariDataSource]:无法确定合适的驱动类”
    猜你喜欢
    • 2023-02-04
    • 2021-09-12
    • 2019-12-06
    • 2021-01-24
    • 1970-01-01
    • 2019-03-18
    • 2020-10-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多