1

Spring version: 4.2.6.RELEASE Jetty version: 9.3.9.v20160517

I have an embedded Jetty server with SpringMVC configured as follows:

package test;

public class WebServer {
    public static void main(String[] args) throws Exception {
        AnnotationConfigWebApplicationContext spring = new AnnotationConfigWebApplicationContext();
        spring.scan("test");

        DispatcherServlet servlet = new DispatcherServlet(spring);
        ServletHolder servletHolder = new ServletHolder(servlet);
        servletHolder.setName("spring");

        ServletContextHandler springHandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
        springHandler.setContextPath("/endpoint");
        springHandler.addServlet(servletHolder, "/*");
        springHandler.setErrorHandler(null);
        springHandler.addEventListener(new ContextLoaderListener(spring));

        Server server = new Server(9290);
        server.setHandler(springHandler);
        server.setStopAtShutdown(true);
        server.start();
        server.join();
    }
}

I also have this controller:

package test;

@RestController
public class AController {
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public ResponseEntity<String> testGet() {
        return new ResponseEntity<>("GET response", null, HttpStatus.OK);
    }

    @RequestMapping(value = "/", method = RequestMethod.POST)
    public ResponseEntity<String> testPost() {
        return new ResponseEntity<>("POST response", null, HttpStatus.OK);
    }
}

When I issue a POST to localhost:9290/endpoint the testGet() method is executed, since i am receiving GET response.

However if I make the POST to localhost:9290/endpoint/ (notice the slash at the end), the testPost() method is executed, as expected.

Is this a Jetty or Spring bug? I expected either to receive a 404 or the testPost() method to be executed instead of the testGet method.

0 Answers0