5

I want to match all requests with a PathVariable which are not start with 'api'. I test following RequestMapping. spring could match request but could not get value for PathVariable. How I solve this?

@RequestMapping(value = "/{name:(?!api).+}", method = RequestMethod.GET)
public void getNotApi(@PathVariable String name, HttpServletResponse response) {
    ...
}

I get following message for some request like localhost:8080/resource.

Error 500 Missing URI template variable 'name' for method parameter of type String

Ali Akbarpour
  • 958
  • 2
  • 18
  • 35
hadi.mansouri
  • 828
  • 11
  • 25

2 Answers2

7
@RequestMapping(value = "/{name:^(?!api).+}", method = RequestMethod.GET)
fg78nc
  • 4,774
  • 3
  • 19
  • 32
-1

If you are building on Java pre 8 version, it may be because of missing name. Try @PathVariable("name") String name. Keep @PathVariable value same as your mapping parameter name.

naXa stands with Ukraine
  • 35,493
  • 19
  • 190
  • 259