Spring URI Template Patterns with Regular Expressions

See the SpEL documentation: http://static.springsource.org/spring/docs/3.0.5.RELEASE/reference/expressions.html

You will want to do something like this:

@RequestMapping(value = "/user/{id:.*}", method = RequestMethod.GET,headers="Accept=application/xml" )
public void test(@PathVariable("id") String id) {

If you are using @Configuration-style with Spring MVC, this will do the trick:

@Configuration
public class Api extends WebMvcConfigurationSupport {

    @Bean
    public RequestMappingHandlerMapping requestMappingHandlerMapping() {
        RequestMappingHandlerMapping mapping = super.requestMappingHandlerMapping();
        mapping.setUseSuffixPatternMatch(false);
        return mapping;
    }

}

As you can see you must disable useSuffixPatternMatch in RequestMappingHandlerMapping.

See also:

  • Configuring RequestMappingHandlerMapping when using mvc:annotation-driven