zoukankan      html  css  js  c++  java
  • 解决java.lang.IllegalArgumentException: No converter found for return value of type 的问题

    controller返回一个dto,并且定义了@ResponseBody注解,表示希望将这个dto对象转换为json字符串返回给前端,但是运行时报错:nested exception is java.lang.IllegalArgumentException: No converter found for return value of type:XXX.XXX.dto。

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

    解决方法为手动添加jackson依赖到pom.xml文件中:

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

    如果还是没有解决,则在springmvc配置文件中进行如下配置:

    <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>
  • 相关阅读:
    允许debian wheezy支持IOS7+的iphone.
    openSUSE 国内镜像摘要
    策略模式总结
    顺序串
    WindowState注意事项
    NLP | 自然语言处理
    Using Autorelease Pool Blocks
    NSAutoreleasePool & thread
    oc语言特性
    oc语言基础整理
  • 原文地址:https://www.cnblogs.com/laoxia/p/10247557.html
Copyright © 2011-2022 走看看