java - jetty :run fails with NoSuchMethodError with Spring 5

标签 java spring maven maven-jetty-plugin

我正在尝试将我的网络应用程序更新到当前的库。当我将 Spring 从 3.1.1 升级到 5.0.0 时,它开始失败:

java.lang.NoSuchMethodError: javax.servlet.http.HttpServletResponse.getStatus()I
    at org.springframework.web.servlet.FrameworkServlet.publishRequestHandledEvent(FrameworkServlet.java:1083)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1009)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:881)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1221)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:399)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:450)

我发现了两个相关问题:

这解释了很多,我已经升级了jetty和servlet规范。但我的应用程序总是失败。

依赖关系:

[INFO] +- org.slf4j:jcl-over-slf4j:jar:1.7.5:compile
[INFO] |  \- org.slf4j:slf4j-api:jar:1.7.5:compile
[INFO] +- ch.qos.logback:logback-core:jar:1.1.1:compile
[INFO] +- ch.qos.logback:logback-classic:jar:1.1.1:compile
[INFO] +- org.codehaus.janino:janino:jar:2.6.1:compile
[INFO] |  \- org.codehaus.janino:commons-compiler:jar:2.6.1:compile
[INFO] +- org.springframework:spring-web:jar:5.0.0.RELEASE:compile
[INFO] |  +- org.springframework:spring-beans:jar:5.0.0.RELEASE:compile
[INFO] |  \- org.springframework:spring-core:jar:5.0.0.RELEASE:compile
[INFO] |     \- org.springframework:spring-jcl:jar:5.0.0.RELEASE:compile
[INFO] +- org.springframework:spring-webmvc:jar:5.0.0.RELEASE:compile
[INFO] |  +- org.springframework:spring-aop:jar:5.0.0.RELEASE:compile
[INFO] |  +- org.springframework:spring-context:jar:5.0.0.RELEASE:compile
[INFO] |  \- org.springframework:spring-expression:jar:5.0.0.RELEASE:compile
[INFO] +- javax.servlet:javax.servlet-api:jar:3.1.0:provided
[INFO] +- com.google.code.gson:gson:jar:2.2.2:compile
[INFO] \- junit:junit:jar:4.10:test
[INFO]    \- org.hamcrest:hamcrest-core:jar:1.1:test

Maven:

    <spring.framework.version>5.0.0.RELEASE</spring.framework.version>
    <maven-jetty-plugin.version>6.1.26</maven-jetty-plugin.version>
    <servlet.api.version>3.1.0</servlet.api.version>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${spring.framework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.framework.version}</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>${servlet.api.version}</version>
        <scope>provided</scope>
    </dependency>

<build>
    <finalName>smartpos-backend-device</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
                <showWarnings>true</showWarnings>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.1</version>
            <executions>
                <execution>
                    <id>install</id>
                    <phase>install</phase>
                    <goals>
                        <goal>sources</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>maven-jetty-plugin</artifactId>
            <version>${maven-jetty-plugin.version}</version>

            <configuration>
                <jettyEnvXml>src/main/resources/jetty/jetty-env.xml</jettyEnvXml>
                <contextPath>smartpos-json</contextPath>
                <scanIntervalSeconds>0</scanIntervalSeconds>

                <connectors>
                    <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
                        <port>8080</port>
                    </connector>
                </connectors>
                <systemProperties>
                    <systemProperty>
                        <name>logback.configurationFile</name>
                        <value>logback.xml</value>
                    </systemProperty>
                    <systemProperty>
                        <name>LOG_PATH</name>
                        <value>.</value>
                    </systemProperty>
                </systemProperties>
            </configuration>
        </plugin>
    </plugins>
</build>

最佳答案

Spring 5 至少需要 Servlet 3.1 容器,但是当您使用 Jetty 6.1 时,它(最多)是 Servlet 2.5 容器。所以这显然是行不通的。

您必须升级您的 Jetty 版本。要升级而不是 maven-jetty-plugin,您将需要使用适当的 jetty-maven-plugin(名称已更改),它现在是 Eclipse 的一部分。

<maven-jetty-plugin.version>9.4.7.v20170914</maven-jetty-plugin.version>

<plugin>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>${maven-jetty-plugin.version}</version>
</plugin>

这应该使用最新版本的插件和 Jetty。

关于java - jetty :run fails with NoSuchMethodError with Spring 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46847578/

相关文章:

java - EntityManagerFactory 已关闭

java - 具有基于 ssl 证书的身份验证的 m2e

java - 安卓查看错误

java - 为什么在这种情况下我必须以某种方式关闭 ZipOutputStream?

java - 如何在 java 中获取 linux 文件夹和文件图标和名称?

java - 是否需要连接到本地 mbean 服务器才能访问嵌套 mbean?

java - Spring roo Hibernate更新入口多对多映射

java - Maven 构建成功,但缺少依赖项。 JDWP 退出错误

java - Maven 构建中的 "java.lang.OutOfMemoryError: PermGen space"

java - 结合 TCP 套接字和 Restful 端点