在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
答案 0 :(得分:1)
无法实例化[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文件中。
答案 1 :(得分:0)
您应将驱动程序类配置添加到application.properties:
spring.datasource.driver-class-name=org.postgresql.Driver