@RequestMapping(value = { "/abc/xyz/redirect",
"/abc/xyz/redirect/{refPath}",
"/abc/xyz/redirect/*" })
public String handleRequest (ServletRequest request, ServletResponse response,
@PathVariable String refPath,
@RequestParam(value = "subscriptionId", required = false) String customId)
I implemented this logic to add the refPath, but afterwards I started receiving 500 with "refPath" is not available even though the endpoint hit was /abc/xyz/redirect?customId=123
Can someone please help me understand why it is not being mapped to /abc/xyz/redirect?
I tried to work after making @PathVariable to false. It worked but still did not get why it was not matched with the current config?
The @PathVariable annotation in Spring MVC indicates that a method parameter should be bound to a URI template variable. When you have multiple URI patterns mapped to the same method, Spring needs to resolve which variables to bind based on the incoming request.
In your case, you have three URI patterns mapped to the handleRequest method:
When a request comes in, Spring needs to determine which pattern to match. If the request URL is
"/abc/xyz/redirect?customId=123", it matches the first pattern without {refPath} variable, hence refPath remains null because it is not part of the URI.So Either