Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matching anything in Spring RequestMapping

On Spring MVC rest service I am having issues trying to match anything that is beyond my configured RequestMapping value.

So for e.g. I have this:

@RequestMapping(value = "{configKey}/{arguments:.*}", method = RequestMethod.GET)

Which says that match anything that is beyond the second path variable. The problem is that this e.g. works ok with:

get("/test/document")

while this ends up with 404:

get("/test/document/download")

It is weird that Spring can't handle this regex. I actually tried a lot of solutions, but none of them worked.

Previously I had this configuration on JAX-RS:

@Path("/{configKey}/{arguments:.*}")

And everything was good, but now I am migrating and having this issue.

Does anyone know what's going on and how to fix this?

EDIT:

Adding {configKey}/** - doesn't work

Adding {configKey}/{arguments}/** works, but for e.g. if I call:

get("/test/document/download") I get only test as my config key and document as arguments. In the arguments I expect to get all what's beyond the {configKey}. Which can be anything for e.g. it should work in any case:

get("/test/document")
get("/test/document/download")
get("/test/document/download/1")
get("/test/document/download/1/2")
get("/test/whatever/xxx/1/2/etc")

Which was working with config for JAX-RS: @Path("/{configKey}/{arguments:.*}")

like image 739
Paulius Matulionis Avatar asked Feb 20 '15 15:02

Paulius Matulionis


1 Answers

The following mapping should work for you

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

This mapping is known as default mapping pattern.

like image 134
Master Slave Avatar answered Oct 04 '22 04:10

Master Slave