Java Spring和Jetty NoClassDefFound错误

Java Spring和Jetty NoClassDefFound错误,java,spring,maven,spring-mvc,maven-jetty-plugin,Java,Spring,Maven,Spring Mvc,Maven Jetty Plugin,您好,我目前在spring应用程序上运行测试时出错 错误是: java.lang.ClassNotFoundException: org/eclipse/jetty/util/FutureCallback 这是我第一次使用spring和maven,所以我很困惑 我认为这是我的pom文件的问题,但我不确定。以下是我的pom.xml: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org

您好,我目前在spring应用程序上运行测试时出错

错误是:

java.lang.ClassNotFoundException: org/eclipse/jetty/util/FutureCallback
这是我第一次使用spring和maven,所以我很困惑
我认为这是我的pom文件的问题,但我不确定。以下是我的pom.xml:

<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</groupId>
<artifactId>CountdownCustomer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>CountdownCustomer</name>
<url>http://maven.apache.org</url>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.0.RELEASE</version>
</parent>

<properties>
    <java.version>1.8</java.version>
    <servlet.container.port>10000</servlet.container.port>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jackson-provider</artifactId>
    <version>3.0.12.Final</version>
</dependency>
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jaxrs</artifactId>
    <version>3.0.12.Final</version>
</dependency>
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-client</artifactId>
    <version>3.0.12.Final</version>
</dependency>
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>jaxrs-api</artifactId>
    <version>3.0.12.Final</version>
</dependency>
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-servlet-initializer</artifactId>
    <version>3.0.12.Final</version>
</dependency>
<!-- Hibernate -->
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
</dependency>
<!-- H2 embedded database. -->
<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
</dependency>
<!-- Spring -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-rest</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<dependency>
    <groupId>com.jayway.jsonpath</groupId>
    <artifactId>json-path</artifactId>
    <scope>test</scope>
</dependency>
<!-- Junit -->
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <scope>test</scope>
</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-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <skip>true</skip>
            </configuration>
            <executions>
                <execution>
                    <id>surefire-it</id>
                    <phase>integration-test</phase>
                    <goals>
                        <goal>test</goal>
                    </goals>
                    <configuration>
                        <skip>false</skip>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>9.1.4.v20140401</version>
            <configuration>
                <httpConnector>
                    <port>${servlet.container.port}</port>
                </httpConnector>
                <webApp>
                    <contextPath>/</contextPath>
                </webApp>
                <scanIntervalSeconds>10</scanIntervalSeconds>
                <stopKey>foo</stopKey>
                <stopPort>9999</stopPort>
                <stopWait>1</stopWait>
            </configuration>
            <executions>
                <execution>
                    <id>start-jetty</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <scanIntervalSeconds>0</scanIntervalSeconds>
                        <daemon>true</daemon>
                    </configuration>
                </execution>
                <execution>
                    <id>stop-jetty</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>stop</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

<repositories>
    <repository>
        <id>spring-releases</id>
        <url>https://repo.spring.io/libs-release</url>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>spring-releases</id>
        <url>https://repo.spring.io/libs-release</url>
    </pluginRepository>
</pluginRepositories>

4.0.0
组织机构
倒计时客户
0.0.1-快照
罐子
倒计时客户
http://maven.apache.org
org.springframework.boot
spring启动程序父级
1.4.0.1发布
1.8
10000
UTF-8
UTF-8
org.jboss.resteasy
resteasy jackson提供商
3.0.12.1决赛
org.jboss.resteasy
resteasy jaxrs
3.0.12.1决赛
org.jboss.resteasy
resteasy客户端
3.0.12.1决赛
org.jboss.resteasy
jaxrs api
3.0.12.1决赛
org.jboss.resteasy
resteasy servlet初始值设定项
3.0.12.1决赛
org.hibernate
休眠实体管理器
com.h2数据库
氢
org.springframework.boot
弹簧启动启动器数据rest
org.springframework.boot
弹簧启动机tomcat
org.springframework.boot
spring引导启动器数据jpa
org.springframework.boot
弹簧启动机tomcat
org.springframework.boot
弹簧起动试验
测试
org.springframework.boot
弹簧启动机tomcat
org.springframework.boot
弹簧靴起动器码头
com.jayway.jsonpath
json路径
测试
朱尼特
朱尼特
测试
org.springframework.boot
springbootmaven插件
org.apache.maven.plugins
maven编译器插件
1.8
1.8
org.apache.maven.plugins
maven surefire插件
真的
当然可以
集成测试
测试
假的
org.eclipse.jetty
jetty maven插件
9.1.4.v20140401
${servlet.container.port}
/
10
福
9999
1.
起动码头
预集成测试
跑
0
真的
停靠码头
整合后测试
停止
春假
https://repo.spring.io/libs-release
春假
https://repo.spring.io/libs-release

更新:


通过将jetty版本更改为更新的版本,问题得到了解决。您必须将以下依赖项添加到项目中:

<!-- https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-util -->
<dependency>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-util</artifactId>
    <version>9.3.10.v20160621</version>
</dependency>

org.eclipse.jetty
码头
9.3.10.v20160621

好吧,Spring开箱即用包括Tomcat作为其嵌入式服务器,您需要删除这种依赖关系

<exclusions>
    <exclusion>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
    </exclusion>
</exclusions>

org.springframework.boot
弹簧启动机tomcat
换成码头

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

org.springframework.boot
弹簧靴起动器码头

此外,您不需要所有这些引导依赖项
spring boot starter数据rest
已经包括
spring boot starter数据jpa
spring boot starter web
,您也可以删除它们。

确保jar文件具有您正在使用的类。 您可以打开存储库(C:\Users\.m2\repository)导航到您的jar位置,打开jar并查看。
如果这个jar没有这个类,那么寻找其他具有这个类的依赖项,并将它添加到pom.xml中。

我做了这些更改,我的应用程序现在正在jetty上运行,但是当我运行我的测试时,它们以相同的错误失败。你还必须在
spring boot starter测试
依赖项中进行相同的更改。我添加了排除,它仍然在测试中失败。实际上,基于“它仍然失败”来诊断问题是不可能的。向我们展示您的
.pom
更新了pom文件,我在spring boot starter数据中留下了jpa,因为没有它,我的应用程序会崩溃,出现不同的异常