我在一个项目HTTP Status 406
中,当我的 URL 是这样的时候得到响应:
http://www.mydomain.com/project/website/reply/google.com
我发现它在 url 以 etc 结尾时抛出 406,当 url 以.com, .in
etc 结尾时.do, .co, .coom
,它的响应为 HTML 页面但未映射完整的 url
例如:假设我有 2 个网址
http://www.mydomain.com/project/website/reply/google.com
// 将返回 406
http://www.mydomain.com/project/website/reply/apple.do
// 将返回 HTML 但
.do
会被 忽略@PathVariable
,因此您只能apple
在apple.do
. 我想要之后的全部价值reply/
正如我所说,我得到了HTTP Status 406(The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers.)
,所以我用谷歌搜索并得到了一些建议,比如Ignoring accept headers
and ContentNegotiations
,但仍然得到相同的响应。
我在用:
- Spring MVC 3.2.0.RELEASE(带有 JAVA 配置)
- 杰克逊版本 2.1.0
- Thymeleaf 模板引擎 2.1.2.RELEASE
如果您想从我这里得到任何其他信息,请告诉我。
这是我在 JAVA 配置中ContentNegotiatingViewResolver
(使用此ref)的代码,但它不起作用:
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
System.out.println("### configureContentNegotiation is called");
configurer.ignoreAcceptHeader(true).defaultContentType(MediaType.TEXT_HTML);
}
@Bean
public ViewResolver contentNegotiatingViewResolver(
ContentNegotiationManager manager) {
System.out.println("### contentNegotiatingViewResolver is called");
List<ViewResolver> resolvers = new ArrayList<ViewResolver>();
ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
viewResolver.setTemplateEngine(templateEngine());
// Create the CNVR plugging in the resolvers and the content-negotiation manager
ContentNegotiatingViewResolver resolver = new ContentNegotiatingViewResolver();
resolver.setViewResolvers(resolvers);
resolver.setContentNegotiationManager(manager);
return resolver;
}
请给我一些建议。