maven-未能执行goal org.springframeworkboot:spring-boot-maven-plugin:2.4.1:运行

dzhpxtsq  于 2021-06-29  发布在  Java
关注(0)|答案(1)|浏览(437)

我在创建了我的项目https://start.spring.io/
网上的几个错误是相似的,但没有解决我的问题。
执行时,我发现一个错误返回:
未能执行goal org.springframework.boot:spring boot maven plugin:2.4.1:run
这是我的pom和主文件main
聚甲醛:

<?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 https://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.4.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>net.javaguides</groupId>
    <artifactId>spring-boot-restfull-webservice</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>spring-boot-restfull-webservice</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>11</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-web</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>
    </dependencies>

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

</project>

班级:

package net.javaguides.springboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringBootRestfullWebserviceApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringBootRestfullWebserviceApplication.class, args);
    }
}

我对springboot不熟悉,我该怎么修?

bakd9h0s

bakd9h0s1#

我已经让你的身材正常了,但我不得不做出一些妥协。
我查看了spring文档以了解您正在尝试的内容:
https://spring.io/guides/gs/rest-service/
然后我看了pom.xml作为示例:
https://github.com/spring-guides/gs-rest-service/blob/master/complete/pom.xml
尽管文档中说您可以使用Java1.8或更高版本,但是您需要使用Java1.8。如果更高,则必须在插件中指定属性编码,而不能这样做,因为您使用的是spring引导插件,而不是可以在pom.xml中为项目配置的插件。
我还添加了一个比spring引导使用的maven-surefire插件更低的版本。使用此版本,您将得到错误 [ERROR] There are test failures ,但您没有运行任何测试。
我注解掉了mysql和jpa的依赖关系,除非您有数据库连接设置,否则这两个依赖关系将不起作用。

<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 https://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.4.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>net.javaguides</groupId>
    <artifactId>spring-boot-restful-webservice</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>spring-boot-restful-webservice</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-web</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>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.5</version>
                <configuration>
                    <skipTests>false</skipTests>
                    <testFailureIgnore>true</testFailureIgnore>
                    <forkMode>once</forkMode>
                </configuration>
            </plugin>           
        </plugins>
    </build>
</project>

相关问题