Jetty:run fails with NoSuchMethodError with Spring 5

后端 未结 2 1270
渐次进展
渐次进展 2021-01-21 12:56

I am trying to update my web application to current libraries. When I upgraded Spring from 3.1.1 to 5.0.0 it started to fail with:

java.lang.NoSuchMethodError: j         


        
相关标签:
2条回答
  • 2021-01-21 13:07

    My bad I got it wrong. I think the problem is your jetty version:

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

    Here the servlet API is 2.5 and when you add dependency in Maven and mark it with provided scope it means the required JARs will be provided on a later stage and not packed with the war. So the code compiles properly in the IDE and development but when you try to run it with jetty it uses the actual servlet-api coming from the jetty version. And for that method you need servlet-api version 3 or above

    0 讨论(0)
  • 2021-01-21 13:11

    Spring 5 requires a Servlet 3.1 container as a bare minimum however as you are using Jetty 6.1 which is (at most) a Servlet 2.5 container. So that is obviously not going to work.

    You will have to upgrade your Jetty version. To upgrade instead of the maven-jetty-plugin you will need to use the appropriate jetty-maven-plugin (the name has changed) and it is part of Eclipse now.

    <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>
    

    This should use the latest version of both the plugin and thus Jetty.

    0 讨论(0)
提交回复
热议问题