I have an existing Spring MVC service running with the following RequestMapping.
@RequestMapping(value = "{user}/**", method = RequestMethod.GET)
I now need to add a new method to the same controller with the following RequestMapping.
@RequestMapping(value = "api/{user}/**", method = RequestMethod.GET)
When I test against the new URL, Spring is always choosing the first function so that this second function is inaccessible.
Is there anyway that I can get Spring to use my new "api" method? The only option I can think of is to create a new Java servlet in my web.xml, but I'd like to do something simpler. I did try making two different controllers, with @Controller
and @Controller("api")
, but that did not solve the problem.
Assuming that your parameter for user
is String
, Spring is assuming that you've been invoked for user api
.
There are a couple of ways to solve this. The first (and best) is to make your request mappings more narrow: fully specify the mapping, rather than relying on "**
" at the end.
The second approach is to disallow an "api" user, using a regex in your mapping. Something like the following should work:
@RequestMapping(value = "{user:[^a][^p][^i]}/**", method = RequestMethod.GET)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With