I involved in project where I found a mix of:
@RequestMapping(value = "events/..."); @RequestMapping(value = "/events/...");
(with and without slash before method level annotation).
I perform search:
site:http://static.springsource.org/spring/docs/3.1.x slash
and read these links:
- http://forum.springsource.org/showthread.php?130753-Various-Spring-MVC-RequestMapping-configuration-questions
- Various Spring MVC RequestMapping configuration questions
- Handling of pre-slash in @RequestMapping
- https://www.rfc-editor.org/rfc/rfc6570
But none of these sources answer why skipping slash allowed. Official Spring docs always shown examples with slashes…
Need point to official docs or to Spring sources.
Best Answer
It does not matter: If the path does not start with an
/
then Spring (DefaultAnnotationHandlerMapping) will add it.See method
String[] determineUrlsForHandler(String beanName)
of ClassDefaultAnnotationHandlerMapping
line 122 (Spring 3.1.2) (that is for the class level)See method
String[] determineUrlsForHandler(Class<?> handlerType, final boolean hasTypeLevelMapping))
of ClassDefaultAnnotationHandlerMapping
line 182 (Spring 3.1.2) (that is for the method level)