Ludovic Guillaume
Ludovic Guillaume

Reputation: 3287

Spring @RequestMapping on controller

I'm using Spring MVC 3.1.3.

I'd like to do the same as the example shown in the documentation. @RequestMapping on the controller and a 'root' method.

But Spring does not handle correctly.

Here's my code :

@Controller
@RequestMapping("/test")
public class TestController {
    @RequestMapping(method = RequestMethod.GET)
    @ResponseBody
    public String list() {
        return "test";
    }
}

When I try http://localhost/test-project/test I get a 404 Not Found but it's working when I use http://localhost/test-project/test/.

Does anyone know how I can fix this ?

Thanks,

Smoky

EDIT:

Here's the log :

16:13:36,085 | DEBUG | RequestMappingHandlerMapping:209 | Looking up handler method for path /test
16:13:36,087 | DEBUG | RequestMappingHandlerMapping:219 | Did not find handler method for [/test]

Upvotes: 3

Views: 1092

Answers (2)

David
David

Reputation: 20073

Change the method requestMapping tag on the method to...

@RequestMapping(value = {"", "/", "/list"}, method = RequestMethod.GET)

Edit addition from comment :

Have you tried setting the controller to @RequestMapping("/test*")

Upvotes: 1

Michał Rybak
Michał Rybak

Reputation: 8706

Use wildcard in your Controller level @RequestMapping:

@RequestMapping("/test*")

Upvotes: 0

Related Questions