私の Spring 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」のマッピングがある場合、Spring が「abc.*」および「abc/」を登録してはならないことを意味します。
私のコントローラーの1つに、応答に画像を書き込むメソッドがあります。
@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」をリクエストすると、「path」パラメーターはテキスト「abc」のみを受け取ります。スプリングは拡張子を省略しています。
Spring が接尾辞パターンを正しく無視していないようです。どうしてこれなの?
編集: Dirk のコメントから 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>
元のコードが機能しなかった理由はまだわかりませんが、これで問題は解決しました