搜索
您的当前位置:首页正文

java.lang.IllegalArgumentException: No converter found for return value of type解决方案

来源:意榕旅游网

java.lang.IllegalArgumentException: No converter found for return value of type解决方案

背景

  • spring mvc框架
  • 接口返回的理想类型:自定义实体类的json数据

具体问题

  • 如图

问题原因

  • spring mvc没有实体类装换为json的功能,需要进行手动配置

解决方案

  • pom文件引入jackson依赖
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.5.4</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.5.4</version>
    </dependency>
    
  • spring mvc配置文件中添加转换扫描
    <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>
    

  • 根据自己的问题灵活运用 ^~^

因篇幅问题不能全部显示,请点此查看更多更全内容

Top