Java Maven在本地计算机上构建Spring引导,但不构建EC2实例:UnsatifiedPendencyException

Java Maven在本地计算机上构建Spring引导,但不构建EC2实例:UnsatifiedPendencyException,java,spring,maven,spring-boot,Java,Spring,Maven,Spring Boot,在过去的几个小时里,我一直在努力让Maven在AmazonEC2实例中为我的SpringBoot项目构建一个JAR文件。如果我在本地计算机上使用IntelliJ或mvn软件包构建,一切都很好,没有问题。但是,如果我将完全相同的代码从同一个存储库拉入EC2实例并在那里构建它(我两次都使用Java 8,也尝试过Java 11),它会显示以下错误: [ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 5.373

在过去的几个小时里,我一直在努力让Maven在AmazonEC2实例中为我的SpringBoot项目构建一个JAR文件。如果我在本地计算机上使用IntelliJ或
mvn软件包
构建,一切都很好,没有问题。但是,如果我将完全相同的代码从同一个存储库拉入EC2实例并在那里构建它(我两次都使用Java 8,也尝试过Java 11),它会显示以下错误:

[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 5.373 s <<< FAILURE! - in com.courier.courier.CourierApplicationTests
[ERROR] contextLoads(com.courier.courier.CourierApplicationTests)  Time elapsed: 0.009 s  <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
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
Caused by: 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
Caused by: 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
Caused by: org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
编辑:显然CourierApplicationTests类是直接的错误:删除它解决了我的问题。它并没有真正解释为什么它会在本地构建而不是在EC2中构建,所以我将继续回答这个问题并提供测试文件:

package com.courier.courier;
导入org.junit.Test;
导入org.junit.runner.RunWith;
导入org.springframework.boot.test.context.SpringBootTest;
导入org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@春靴测试
公共类信使应用程序测试{
@试验
public void contextLoads(){
}
}

向我们展示您的配置:bootstrap.yml、application.yml或您使用的类似配置。@mentalurg我恐怕找不到任何此类文件。任何与远程相关的都是maven-wrapper.properties,它看起来不像一个配置文件。我建议只添加依赖项,但不添加版本。由于我在pom.xml中看到mysql依赖项,您是否在application.properties文件中配置数据库详细信息(url、驱动程序类名等)?我想我可能会回答我的问题,到底是什么解决了问题,它指定了驱动程序类名,虽然我用的那个已经不推荐了,但它很管用。有趣的是,我后来移除了它,它继续正常构建。