No converter found for return value of type: class java.util.HashMap + 'Content-Type' cannot contain wildcard type '*'

背景说明:

环境:IDEA java语言 springmvc.xml 配置 需要用到fastjson jackson pom.xml中配置了需要用到的包,springmvc.xml中也写了注解驱动

Controller中返回Object类型

到返回Map类型的时候

Controller中代码如下:

 @RequestMapping(name="/returnMap.do")
 @RequestMapping("/returnMap.do")
    @ResponseBody //将返回值添加到响应体中
    public  Object returnMap()throws  Exception{
        Map<String,String> map = new HashMap<>();
        map.put("hello","你好");
        map.put("World","先生");
        return map;
    }

运行报: java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.HashMap 说明:首要要看一下library是否导进去,也就是自己写完pom.xml之后有没有reimport,其次看一下注解驱动有没有配置,也就是jackson的那三个包,最后再从其他方面找原因。百度后,又说fastjson版本的问题的,试了无果,加了个

 <mvc:annotation-driven>
        <mvc:message-converters>
            <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter"/>
        </mvc:message-converters>
    </mvc:annotation-driven>

也没解决,后边还添加 :

<!-- https://mvnrepository.com/artifact/org.codehaus.jackson/jackson-mapper-asl -->
    <dependency>
      <groupId>org.codehaus.jackson</groupId>
      <artifactId>jackson-mapper-asl</artifactId>
      <version>1.9.13</version>
    </dependency>

然后就换成了报:java.lang.IllegalArgumentException: ‘Content-Type‘ cannot contain wildcard type ‘*‘

然后又是一顿百度,试了各种方法还是没能解决问题

然后就看到了下边这个试了一下:错误消除,代码如下

 @RequestMapping(name="/returnMap.do",consumes = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody //将返回值添加到响应体中
    public  Object returnMap()throws  Exception{
        Map<String,String> map = new HashMap<>();
        map.put("hello","你好");
        map.put("World","先生");
        return map;
    }

改变部分:

 @RequestMapping(name="/returnMap.do",consumes = MediaType.APPLICATION_JSON_VALUE)
    

注意对比 你就会发现哦!

所以导致最后自己都不知道到底是因为那个解决了问题??

BUT,启动后才返现返回来的消息是:

Status Code:

415 Unsupported Media Type  /(ㄒoㄒ)/~~

参考链接:

http://www.mamicode.com/info-detail-2562906.html

No converter found for return value of type: class java.util.HashMap + 'Content-Type' cannot contain wildcard type '*'

原文地址:https://www.cnblogs.com/liupengjuan/p/12001267.html

时间: 2024-07-31 20:35:24

No converter found for return value of type: class java.util.HashMap + 'Content-Type' cannot contain wildcard type '*'的相关文章

解决nested exception is java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.ArrayList问题

一.背景 最近闲来无事,想自己搭建一套Spring+SpringMVC+Mybatis+Mysql的环境(搭建步骤会在以后博客中给出),结果运行程序时,适用@ResponseBody注解进行返回List<对象>的json数据时出现了:nested exception is java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.ArrayList错误,就细细

【Spring】No converter found for return value of type: class java.util.ArrayList

错误信息: org.springframework.http.converter.HttpMessageNotWritableException: No converter found for return value of type: class java.util.ArrayList 如图所示: http://www.cnblogs.com/hafiz/p/5812873.html 提供了一种解决方案,似乎也是很多人的做法,但我试过之后发现不行. 后来发现是版本的问题:升了 jackson

SSM报错:No converter found for return value of type: class java.util.ArrayList at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverter

我使用的是SSM框架,是在编写测试RESTFUL接口的时候出现, @RequestMapping(value = "/selectAll", method = RequestMethod.GET) @ResponseBody public ResponseEntity<List<User>> selectAll() { List<User> users = this.userService.selectAll(); if (null != users

org.hibernate.MappingException: Could not determine type for: java.util.List, at table: user, for...

异常详情: Caused by: org.hibernate.MappingException: Could not determine type for: java.util.List, at table: ss_user, for columns: [org.hibernate.mapping.Column(roles)] at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:336) ~[hibernate-core-4

170616、解决 java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.ArrayList

报错截图: 原因:搭建项目的时候,springmvc默认是没有对象转换成json的转换器的,需要手动添加jackson依赖. 解决步骤: 1.添加jackson依赖到pom.xml <!-- jaskson --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>

Hibernate异常Caused by: org.hibernate.MappingException: Could not determine type for: java.util.Set

一:异常截图 二:我的实体 @Entity @Table(name = "p_user") public class User extends AbstractEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private long id; //账号 @Column(name = "account", nullable = true) private String account; /

SpringMVC访问出错No converter found for return value of type

在使用SSM整合的时候,spring mvc 添加@ResponseBody的时候,正常情况下都会返回json的.但是又的时候如果没有配置好的话,如果想要返回Map的json对象会报:No converter found for return value of type: class java.util.HashMap错误. 如下图: ? 果返回的事字符串或者事Integer类型就可以正常返回,但是如果返回对象的话,就会出现这个错误.说明在spring mvc转换成json的时候出错了. 解决方

java.lang.IllegalArgumentException: No converter found for return value of type: class com.smart.result.Page

今天学习了一下spring boot 中的mybatis,用mybatis来增删改查用户,获取用户,添加用户,修改用户,删除用户,修改用户,都是可以的,但是获取带分页的用户列表,一直抛出这个java.lang.IllegalArgumentException: No converter found for return value of type: class com.smart.result.Page,一直不知道什么地方的问题,后来一查才知道Page<E>中没有实现属性的set,get造成的

java.lang.IllegalArgumentException: No converter found for return value of type:

java.lang.IllegalArgumentException: No converter found for return value of type: 本人使用了阿里的fastson,结果出错,改成Jackson,错误解决 在pom文件中加入依赖 <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId