SpringMVC中当在浏览器中输入对应的MappingUrl时,报The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers.

错误的意思是:说是指定的资源已经找到,但它的MIME类型和客户在Accpet头中所指定的不兼容

@ResponseBody返回json格式的数据,而浏览器接受的是text/html;charset=UTF-8文本类型

解决方法:

1:在pom.xml中添加json所需要的依赖

  <!--json所需要的依赖-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.7.3</version>
</dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.7.3</version>
</dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.7.3</version>
</dependency>

2:在springmvc配置文件中配置对应的bean

 <!--转化json-->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<!--json视图拦截器,读取到@ResponseBody的时候去配置它-->
<ref bean="mappingJacksonHttpMessageConverter"/>
</list>
</property>
</bean>
<!--json转化器,它可以将结果转化-->
<bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>

重新启动不在报错了

解决The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers.的更多相关文章

  1. 浏览器报406 错误:The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers

    The resource identified by this request is only capable of generating responses with characteristics ...

  2. 【406错误】 The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers.

    今天遇到一个奇怪的错误,关于Springmvc的,我明明在Controller方法中写了@ResponseBody,返回一个Map,结果报了406错误. 结果发现,少了一个jar包: 加上去就没事了.

  3. The resource identified by this request is only capable of generating responses with characteristics

    [转]今天在调试springMVC的时候,在将一个对象返回为json串的时候,浏览器中出现异常: The resource identified by this request is only cap ...

  4. SpringMVC_The resource identified by this request is only capable of generating responses with characteristics

    今天在调试springMVC的时候,在将一个对象返回为json串的时候,浏览器中出现异常: The resource identified by this request is only capabl ...

  5. Could not parse multipart servlet request; nested exception is org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed.

    org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nes ...

  6. 解决 No resource found that matches the given name (at 'icon' with value '@drawable/icon') 问题

    对新解决方案Xamarin的Android项目在项目属性 换图标后 会出现 No resource found that matches the given name (at 'icon' with ...

  7. 解决 “invalid resource directory name”, resource “crunch”

        try this: from the menu click Project->Clean... a popup window will appear. select the check ...

  8. 如何解决 “invalid resource directory name”, resource “crunch”

    Ant and the ADT Plugin for Eclipse are packing the .apk file in a different build chain and temp gen ...

  9. 微信小程序:request合法域名检验出错,https://apis.map.qq.com 不在以下 request 合法域名列表中

    设置域名 登录微信小程序后台, 设置→开发设置→服务器设置 必须设置域名,微信小程序才能进行网络通讯,不然会报错 如果没有设置合法域名,在开发阶段是可以不设置合法域名的 详情 -项目设置 好了,完美解 ...

随机推荐

  1. Two Melodies CodeForces - 813D (DP,技巧)

    https://codeforces.com/problemset/problem/813/D dp[i][j] = 一条链以i结尾, 另一条链以j结尾的最大值 关键要保证转移时两条链不能相交 #in ...

  2. python记录_day17 类与类之间的关系

    一.依赖关系 a类的对象是b类方法的参数 这种关系是我用着你,但你不属于我,比如公司和临时工的关系,是很弱的一种关系 class Zhiwu: def __init__(self,name,atk): ...

  3. spring boot(一)入门

    什么是spring boot Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员 ...

  4. SpringBoot项目Shiro的实现(二)

    在看此小节前,您可能需要先看:http://www.cnblogs.com/conswin/p/7478557.html 紧接上一篇,在上一篇我们简单实现了一个Springboot的小程序,但我们发现 ...

  5. Oracle中事务处理控制用法

    oracle 事物控制包括 COMMINT ROLLBACK SAVEPOINT avepoint是事务内部允许部分rollback的标志符.因为事务中对记录做了修改,我们可以在事务中创建savepo ...

  6. 元类应用ORM实现

    首先看下一个简单的例子 # 需求 import numbers class Field: pass class IntField(Field): # 数据描述符 def __init__(self, ...

  7. ThinkPHP3自动加载公共函数文件

    7d 根目录 ├─Application 应用目录 │ ├─Common 公共模块 │ │ ├─Common 公共函数文件目录 │ │ │ ├─index.html │ │ ├─Config 配置文件 ...

  8. MongoDB 教程(二):MongoDB 简介

    概述: MongoDB 旨在为WEB应用提供可扩展.高性能的数据存储解决方案. MongoDB 将数据存储为一个文档,数据结构由键值(key=>value)对组成. MongoDB 文档类似于 ...

  9. SpringBoot利用注解@Value获取properties属性为null

    参考:https://www.cnblogs.com/zacky31/p/8609990.html 今天在项目中想使用@Value来获取Springboot中properties中属性值. 场景:定义 ...

  10. java旅程(一) 配置环境

    (一)安装java JDK   下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151. ...