【发布时间】: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