Trying to create REST-ful URLs with multiple dots in the “filename” part - Spring 3.0 MVC

后端 未结 7 1569
旧巷少年郎
旧巷少年郎 2020-12-03 02:11

I\'m using Spring MVC (3.0) with annotation-driven controllers. I would like to create REST-ful URLs for resources and be able to not require (but still opt

7条回答
  •  春和景丽
    2020-12-03 02:30

    Spring 3.2 has changed, and suggests that you set properties on the RequestMappingHandlerMapping bean, either explicitly (if not using the mvc namespace) or by using a BeanPostProcessor such as the following (you'll need to scan or instantiate it):

    @Component
    public class IncludeExtensionsInRequestParamPostProcessor implements BeanPostProcessor {
        @Override
        public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
            if (bean instanceof RequestMappingHandlerMapping) {
                RequestMappingHandlerMapping mapping = (RequestMappingHandlerMapping)bean;
                mapping.setUseRegisteredSuffixPatternMatch(false);
                mapping.setUseSuffixPatternMatch(false);
            }
            return bean;
        }
    
        @Override
        public Object postProcessAfterInitialization(Object bean, String beanName) { return bean; }
    }
    

    You can also just append :.* to your @RequestMapping, e.g. "/{documentPath:.*}" (see JIRA comment)

提交回复
热议问题