Java Spring启动应用程序-Tomcat部署-无法确定合适的驱动程序类
从IDE运行时,一切看起来都很好 尝试在tomcat服务器中部署应用程序时出现以下错误Java Spring启动应用程序-Tomcat部署-无法确定合适的驱动程序类,java,spring,hibernate,spring-boot,tomcat,Java,Spring,Hibernate,Spring Boot,Tomcat,从IDE运行时,一切看起来都很好 尝试在tomcat服务器中部署应用程序时出现以下错误 Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': Unsatisfied dependency
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);
}
}
格雷德尔先生
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
未能实例化[com.zaxxer.hikari.HikariDataSource]:工厂方法“dataSource”引发异常;嵌套异常为org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException:未能确定合适的驱动程序类
你的房产有几处看起来可疑。但是我认为您可以通过按要求为它指定类名来解决这个特定错误
spring.datasource.driver类名=oracle.jdbc.OracleDriver
(或您正在使用的任何DB)
额外加分
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
(再说一遍,或者你正在使用的任何数据库)
编辑:
当然,除非您将数据库驱动程序jar文件放在tomcat/lib中,否则您需要将其添加到依赖项中,以便将其捆绑到war文件中。您应该将驱动程序类配置添加到应用程序中。属性:
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启动插件来创建一个正确的war。@Mychelltexira:添加了驱动程序名称,但仍然收到错误“未能实例化[com.zaxxer.hikari.HikariDataSource]:未能确定合适的驱动程序类”添加了驱动程序类名,但仍然收到错误“未能实例化”[com.zaxxer.hikari.HikariDataSource]:无法确定合适的驱动程序类“