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

查看:159
本文介绍了Spring Boot无法执行目标org.apache.maven.plugins:maven-surefire-plugin:2.22.1:test的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Eclipse 版本:2018-09(4.9.0),并且已经安装了 Eclipse中的Spring Tool Suit(STS),用于构建Spring Boot应用程序.

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.

问题->每当我创建新的Spring Starter Project并尝试在不添加任何代码的情况下构建我的项目.构建失败,并显示以下错误.

Question-> When ever I create new Spring Starter Project and try to maven build my project without any code addition. 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

如果我删除具有默认测试的测试文件夹.它工作正常.但是为什么会这样.文件夹下面是我由Spring启动项目生成的一个删除的文件

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

src/test/java

谢谢.

更新

下面是生成的默认测试文件.

Below is the default test file which get generated.

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

  @Test
  public void contextLoads() {
  }

}

从引用的文件登录.C:\ Users \ SP064774 \ Util-Workspace \ DemoSpringProject \ target \ surefire-reports

Log from the refered file. 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':通过构造函数参数0表示的不满足的依赖关系;嵌套的异常是org.springframework.beans.factory.BeanCreationException:错误创建在类路径资源中定义的名称为"dataSource"的bean[org/springframework/boot/autoconfigure/jdbc/[DataSourceConfiguration $ Hikari .class]:通过工厂实例化Bean方法失败;嵌套的异常是org.springframework.beans.BeanInstantiationException:失败实例化[com.zaxxer.hikari.HikariDataSource]:工厂方法'dataSource'引发异常;嵌套的例外是org.springframework.boot.autoconfigure.jdbc.DataSourceProperties $DataSourceBeanCreationException:无法确定合适的驱动程序班级引起原因:org.springframework.beans.factory.BeanCreationException:错误创建在类路径资源中定义的名称为"dataSource"的bean[org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration $[Hikari.class]:通过工厂方法实例化Bean失败;嵌套的异常为org.springframework.beans.BeanInstantiationException:失败实例化[com.zaxxer.hikari.HikariDataSource]:工厂方法'dataSource'引发异常;嵌套的异常是org.springframework.boot.autoconfigure.jdbc.DataSourceProperties $DataSourceBeanCreationException:无法确定合适的驱动程序班级引起原因:org.springframework.beans.BeanInstantiationException:失败实例化[com.zaxxer.hikari.HikariDataSource]:工厂方法'dataSource抛出异常;嵌套的例外是org.springframework.boot.autoconfigure.jdbc.DataSourceProperties $DataSourceBeanCreationException:无法确定合适的驱动程序班级造成原因:org.springframework.boot.autoconfigure.jdbc.DataSourceProperties $DataSourceBeanCreationException:无法确定合适的驱动程序课

'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

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>

推荐答案

将jar插件更新为3.1.1可立即解决该问题:

Updating the jar plugin to 3.1.1 immediately fixes the problem:

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

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

这篇关于Spring Boot无法执行目标org.apache.maven.plugins:maven-surefire-plugin:2.22.1:test的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆