1
votes

RESOLVED PER THIS ANSWER Spring invokes wrong controller mapping Spring @Controllers URLs are always interpreted relative the the Spring Dispatcher Servlet that handles them. So if you map the dispatcher servlet to /api/ in web.xml then the URL to your controller above is /api/api/choice

The double string service/service/1234 was working.

ORIGINAL POST

Accessing a REST resource endpoint gives me a 404 error although everything seems to be defined correctly:

Log output:

DEBUG DispatcherServlet with name 'mvc-dispatcher' processing GET request for [/myapp/service/1234]
DEBUG Looking up handler method for path /1234
DEBUG Did not find handler method for [/1234]
WARN  No mapping found for HTTP request with URI [/myapp/service/1234] in DispatcherServlet with name 'mvc-dispatcher'

web.xml

<servlet>
        <servlet-name>mvc-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextClass</param-name>
            <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>/service/*</url-pattern>
    </servlet-mapping>

SpringMVC Controller

@RestController
@RequestMapping("/service")
public class RESTController {
  @RequestMapping(value="/{id}", method=RequestMethod.GET)
  public String getResult ( @PathVariable String id ) 
  {
    //... get JSON result
  }
}

Expected invocation: myapp/service/1234

Also tried these options: 1) Don't define a class RequestMapping, just do a Method Request Mapping

@RequestMapping("/service/{id}")

2) as well as

@RequestMapping("/service*/{id}")
@RequestMapping("/service**/{id}")

Keep getting a 404 with the log above.

1

1 Answers

1
votes

update your web.xml file :

<servlet-mapping>
    <servlet-name>mvc-dispatcher</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>