Posted in spring forum with no response.
I have the following code snippet (from here), which is part of my pet project.
@Controller
@RequestMapping("/browse")
public class MediaBrowser {
...
@RequestMapping("/**")
public final ModelAndView listContents(final HttpServletRequest request) {
String folder = (String) request.getAttribute(
HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
...
}
I access the following url:
http://localhost:8080/myapp/browse
- In spring
3.0.6.RELEASE
, I got thefolder
variable asnull
, which is the expected value. - In spring
3.1.RC1
, thefolder
variable is/browse
.
Is this a bug or has something changed in spring-3.1?
This looks very much like an internal implementation detail of the framework, one that you should not be relying on.
The javadoc for
PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE
says:I wouldn't be surprised if the behaviour changed slightly between 3.0 and 3.1.
As skaffman said, you probably shouldn't use
PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE
. Take a look at How to match a Spring @RequestMapping having a @pathVariable containing "/"? for an example of usingAntPathMatcher
to accomplish what you are trying