Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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]
like image 813
Ludovic Guillaume Avatar asked Sep 10 '26 07:09

Ludovic Guillaume


1 Answers

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*")

like image 91
david99world Avatar answered Sep 11 '26 20:09

david99world



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!