Jetty:运行失败,弹出5号NoSuchMethodError

问题描述:

我试图将我的web应用程序更新为当前库。当我从3.1.1升级春季5.0.0它开始失败:Jetty:运行失败,弹出5号NoSuchMethodError

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) 

我已经发现了两个相关的问题:

这解释了很多,我已经升级了码头和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> 
+1

Spring 5需要一个servlet 3.1或更高容器,Jetty 6是一个2.5容器。所以它不会工作,你需要升级到最新的Jetty版本。你需要切换到'jetty-maven-plugin'而不是旧的'maven-jetty-plugin'。 –

+0

你能把它写成答案吗?我现在可以无误地启动它。但是我必须为我的servlet解决404问题。 RequestMappingHandlerMapping Mapped“{[/ handshake],methods = [POST],产生= [application/json; charset = UTF-8]}”public void controller.DeviceJsonController.performHandShake(java.lang.String,javax.servlet.http .HttpServletResponse)抛出java.io.IOException –

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的最新版本。

+0

谢谢。我已经创建了兼容性问题的新问题:https://*.com/questions/46849304/spring-dispatcher-not-called-in-jetty-maven-plugin –

我的坏我听错了。我认为这个问题是您的码头版本:

https://mvnrepository.com/artifact/org.mortbay.jetty/jetty/6.1.26

这里了servlet API为2.5,当你在Maven中添加依赖关系,并提供范围标记它意味着所需要的JAR文件将被设置在后一阶段和不包含战争。因此,代码在IDE和开发中正确编译,但是当您尝试使用jetty运行代码时,它使用来自jetty版本的实际servlet-api。并且对于这种方法,您需要servlet-api版本3或更高版本

+0

编译错误:-)包javax.servlet.http不存在 –

+0

感谢您的回答 –