Jackie
Jackie

Reputation: 23477

RESTful URL doesn't appear to be mapping right to url Using Spring MVC

I am having trouble getting my url-mapping correct.

My Controller looks like this...

@Controller
@RequestMapping(value = "/rest/report")
public class ReportController extends CatalogManagementBaseController { 
...
@RequestMapping(method = RequestMethod.GET) 
public @ResponseBody String test(Model model) throws Exception{
    return "Worked!";
}
}

And my url-mapping looks like this..`

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>`

If I change the url mapping to / it works but I want the dispatcher to only handle the requests sent to ../rest/...

Any idea what I am doing wrong? Could it be something to do with the inheritance?

Upvotes: 1

Views: 165

Answers (2)

Bozho
Bozho

Reputation: 597016

If your servlet is mapped to /rest/* then the controller should be annotated with:

@RequestMapping(value = "/report")

Upvotes: 3

matt b
matt b

Reputation: 139921

If you want the dispatcher to be mapped to /rest/* then I believe you should remove this prefix from the controller's @RequestMapping, i.e. only have RequestMapping(/report).

The mapping you have configured would result in the Controller listening to requests on /rest/rest/report

Upvotes: 3

Related Questions