在我的春节,XML,我有以下片段:春天不会忽略文件扩展名
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="useDefaultSuffixPattern" value="false"/>
</bean>
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="objectMapper" ref="objectMapper" />
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
据我所知,这意味着,春季应不寄存器“ABC *”和“ABC /”当我有一个“ABC”的映射。
在我的控制器的一个我有一个图像写入响应的方法:
@RequestMapping(value="{path}", method=RequestMethod.GET, produces=MediaType.IMAGE_PNG_VALUE)
@ResponseBody
public void getPath(
@PathVariable String path,
HttpServletResponse res) {
...
}
这时候我要求像“ABC”的伟大工程,但是当我要求“abc.com”它抛出一个406错误与文本:
The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers."
当我请求“abc.img”,“路径”参数仅接收文本“ABC”; Spring省略了扩展。
看来Spring并没有正确地忽略后缀模式。为什么是这样?
编辑:我翻译了德克的评论java的配置,下面XML似乎解决这个问题:
<bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
<property name="favorPathExtension" value="false" />
</bean>
<mvc:annotation-driven content-negotiation-manager="contentNegotiationManager">
<mvc:message-converters>
<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="objectMapper" ref="objectMapper" />
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
我仍然不知道为什么原来的代码我是不起作用,但是这已经解决了我的问题
为了记录,我也试过使用@RequestMapping(value =“{path:。+}”),但没有运气 – user2221343
也许你被同样的问题困扰了。看看这个问题:http://stackoverflow.com/q/22329393/1686330 –
是的,这似乎是相同的问题!我使用了这个问题的等价XML,并且能够解决我的问题。如果你想把它作为答案发布,我会很乐意接受它! – user2221343