【问题标题】:Error with spring-boot-maven-plugin when trying to lauch web app (Spring Vaadin)尝试启动 Web 应用程序时 spring-boot-maven-plugin 出错 (Spring Vaadin)
【发布时间】:2018-08-31 02:25:36
【问题描述】:

您好,我是 J2EE 和 Web 应用程序的初学者,我尝试遵循从 spring 开始的简单入门(使用 vaadin 制作我的 UI)https://spring.io/guides/gs/crud-with-vaadin/

当我启动命令 spring-boot:run 时,出现以下错误:

    [INFO] --- spring-boot-maven-plugin:2.0.0.RELEASE:run (default-cli) @ SampleJPA_Vaadin ---
[WARNING] 
java.lang.NoClassDefFoundError: org/springframework/boot/CommandLineRunner
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
    at java.lang.Class.getMethod0(Class.java:3018)
    at java.lang.Class.getMethod(Class.java:1784)
    at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:492)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.CommandLineRunner
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 7 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.456 s
[INFO] Finished at: 2018-03-21T20:41:09+01:00
[INFO] Final Memory: 23M/228M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.0.RELEASE:run (default-cli) on project SampleJPA_Vaadin: An exception occurred while running. org/springframework/boot/CommandLineRunner: org.springframework.boot.CommandLineRunner -> [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/MojoExecutionException

在网上进行了一些研究后,编译过程后,CommandLineRunner 类不在 jar 中。 但我对 maven 和编译 web 应用程序的过程不太满意。 所以,如果你能解释一下,或者只是给我一些解释的链接,那就太好了,谢谢。

这里也是我的 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>

    <groupId>org.metaverse</groupId>
    <artifactId>SampleJPA_Vaadin</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>SampleJPA_Vaadin</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <vaadin.version>8.3.1</vaadin.version>
    </properties>

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.vaadin</groupId>
                <artifactId>vaadin-bom</artifactId>
                <version>${vaadin.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

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

【问题讨论】:

    标签: spring maven jpa spring-boot vaadin


    【解决方案1】:

    抱歉这个愚蠢的问题,你有一个类,里面有 public static void main :) ?

    我刚刚用你的 pom 做了一个项目,它需要一个带有 main 方法的类来运行。

    如果您将项目发布到 github 上会有所帮助:)

    【讨论】:

      【解决方案2】:

      看起来您在任何地方都没有 spring-boot-starter 依赖项,或者它被您的 vaadin 依赖项传递忽略了。你应该明确地包含它(referenced by this example online):

      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter</artifactId>
      </dependency>
      

      【讨论】:

        【解决方案3】:

        将以下内容添加到您的 Spring Boot Maven 插件配置中

        <plugin>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-maven-plugin</artifactId>
         <executions>
           <execution>
           <goals><goal>repackage</goal></goals>
         <executions>
        </plugin>
        

        这将允许您创建一个包含所有依赖项的可运行 fat jar。你会摆脱这个问题

        【讨论】:

        • 我才意识到 CommandLineRunner 是一个接口,错误是 ClassNotFOundExeption 有链接吗?
        • 对不起,但我坚持认为这是一个构建错误。要么是你的 maven 安装或配置有问题,要么是你的项目配置有问题。
        • 是的,我同意我认为代码还不错,因为我遵循教程,但我不熟悉 maven 和 J2EE 环境。我将向您展示我的 Maven 配置,但我需要为我的项目配置做些什么
        猜你喜欢
        • 2020-06-27
        • 1970-01-01
        • 2020-08-16
        • 2023-02-03
        • 1970-01-01
        • 2020-12-10
        • 2018-03-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多