gpt4 book ai didi

java - Spring Boot 应用程序 - Tomcat 部署 - 无法确定合适的驱动程序类

转载 作者:行者123 更新时间:2023-11-28 22:15:30 24 4
gpt4 key购买 nike

从 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

应用程序.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);
}
}

构建.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'

}

应用程序属性

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

最佳答案

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

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

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

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

加分加分

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

(同样,或者您正在使用的任何数据库)

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

关于java - Spring Boot 应用程序 - Tomcat 部署 - 无法确定合适的驱动程序类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57907482/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com