解决IllegalArgumentException: No converter found for return value of type: class java.util.HashMap

解决:java.longIllegalArgumentException: No converter found for return value of type: class java.util.HashMap

解决IllegalArgumentException: No converter found for return value of type: class java.util.HashMap_第1张图片

错误原因

这是因为SpringMVC默认是没有对象转换成json的转换器的,需要手动添加jackson依赖

解决办法

添加 jackson依赖

<properties>
    <jackson.version>2.9.8</jackson.version>
  </properties> 

    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>${jackson.version}</version>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-core</artifactId>
      <version>${jackson.version}</version>
    </dependency>
    

如果还未解决,需要在
spring—mvc.xml中添加相关配置

<mvc:annotation-driven>
     <mvc:message-converters>
            <bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
            <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
   </mvc:message-converters>
</mvc:annotation-driven>

以上仅供参考!

你可能感兴趣的:(Java,error)