简体   繁体   English

Spring Boot 无法执行目标 org.apache.maven.plugins:maven-surefire-plugin:2.22.1:test

[英]Spring Boot Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.1:test

I am using Eclipse Version: 2018-09 (4.9.0) and i have installed the Spring Tool Suit(STS) in eclipse for building Spring Boot Applications.我正在使用Eclipse版本:2018-09 (4.9.0),并且我已经在 Eclipse 中安装了Spring Tool Suit(STS)以构建 Spring Boot 应用程序。

Question -> When ever I create new Spring Starter Project and try to maven build my project without any code addition.问题-> 当我创建新的 Spring Starter 项目并尝试在不添加任何代码的情况下构建我的项目时。 Build fails with below Error.构建失败并出现以下错误。

[WARNING] The requested profile "pom.xml" could not be activated because it does not exist.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.1:test (default-test) on project DemoSpringProject: There are test failures.
[ERROR] 
[ERROR] Please refer to C:\Users\SP064774\Util-Workspace\DemoSpringProject\target\surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

If I remove the test folder which is having the default test.如果我删除具有默认测试的测试文件夹。 it work fine.它工作正常。 But why this happens.但是为什么会这样。 Below folder is the one i deleted which generated by Spring boot project下面的文件夹是我删除的由 Spring Boot 项目生成的文件夹

src/test/java

Thanks in advance.提前致谢。

Update更新

Below is the default test file which get generated.下面是生成的默认测试文件。

@RunWith(SpringRunner.class)
@SpringBootTest
public class DemoSpringProjectApplicationTests {

  @Test
  public void contextLoads() {
  }

} }

Log from the refered file.从引用的文件中记录。 C:\Users\SP064774\Util-Workspace\DemoSpringProject\target\surefire-reports C:\Users\SP064774\Util-Workspace\DemoSpringProject\target\surefire-reports

--------------------------------------------------------------------
Test set: com.example.demo.DemoSpringProjectApplicationTests
-------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 3.473 s 

FAILURE! - in com.example.demo.DemoSpringProjectApplicationTests
contextLoads(com.example.demo.DemoSpringProjectApplicationTests)  Time 
elapsed: 0.002 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; 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration':通过构造函数参数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;嵌套异常是 org.springframework.beans.factory.BeanCreationException:在类路径资源 [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari .class] 中定义名称为“dataSource”的 bean 创建错误:通过工厂方法进行 Bean 实例化失败; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [com.zaxxer.hikari.HikariDataSource]:工厂方法 'dataSource' 抛出异常; 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;嵌套异常是 org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$ DataSourceBeanCreationException:无法确定合适的驱动程序类原因:org.springframework.beans.factory.BeanCreationException:在类路径资源中定义名称为“dataSource”的 bean 创建错误[org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$ Hikari.class]:通过工厂方法实例化Bean失败; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [com.zaxxer.hikari.HikariDataSource]:工厂方法 'dataSource' 抛出异常; 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;嵌套异常是 org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$ DataSourceBeanCreationException:无法确定合适的驱动程序类原因:org.springframework.beans.BeanInstantiationException:无法实例化 [com.zaxxer.hikari.HikariDataSource]:工厂方法“数据源”抛出异常; 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嵌套异常是 org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$ DataSourceBeanCreationException: 无法确定合适的驱动类 原因:org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$ DataSourceBeanCreationException: 无法确定合适的驱动类

POM.xml POM.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.1.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>DemoSpringProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>DemoSpringProject</name>
<description>Demo project for Spring Boot</description>

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-integration</artifactId>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

You haven't shared your pom.xml file so I cannot be certain, but it looks like you don't have a database driver on the classpath.你还没有共享你的 pom.xml 文件,所以我不能确定,但​​看起来你在类路径上没有数据库驱动程序。 You'll either need to add a dependency on an embedded database (H2 or HSQLDB) or setup up a separate database such as MySQL or Postgres and add the appropriate driver as a dependency.您需要添加对嵌入式数据库(H2 或 HSQLDB)的依赖项,或者设置一个单独的数据库(例如 MySQL 或 Postgres)并添加适当的驱动程序作为依赖项。

在 Eclipse 中,转到 Windows->Preferences->Java->Installed JREs 并更改 jdk 主文件夹的路径

Updating the jar plugin to 3.1.1 immediately fixes the problem:将 jar 插件更新到 3.1.1 可以立即解决问题:

<properties>
  <maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
</properties>

https://github.com/spring-projects/spring-boot/issues/16846#issuecomment-492792506 https://github.com/spring-projects/spring-boot/issues/16846#issuecomment-492792506

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法执行目标org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test(default-test) - Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) 无法在项目上执行目标 org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M3:test (default-test)。 而“作为 Maven 测试运行” - Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M3:test (default-test) on project. while 'Run as Maven test' Maven 在 Eclipse 中运行测试不起作用。 未能执行目标 org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M5:test - Maven test run in Eclipse does not work . Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M5:test 目标 org.apache.maven.plugins:maven-surefire-plugin:2.17:test 的执行默认测试失败:分叉过程中出现错误 - Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.17:test failed: There was an error in the forked process 无法在项目上执行目标org.apache.maven.plugins:maven-surefire-plugin:2.5-r682619-maestro-2.0.0:test(默认测试) - Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.5-r682619-maestro-2.0.0:test (default-test) on project Maven:无法执行目标 org.apache.maven.plugins:maven-resources-plugin:2.7:resources - Maven:Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2.7:resources 无法执行目标org.apache.maven.plugins:maven-jar-plugin:2.4:jar - Failed to execute goal org.apache.maven.plugins:maven-jar-plugin:2.4:jar 无法执行目标org.apache.maven.plugins:maven-antrun-plugin - Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin 无法执行目标org.apache.maven.plugins:maven-clean-plugin:2.4.1 - Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.4.1 无法执行目标org.apache.maven.plugins:maven-compiler-plugin:3.1:compile - Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM