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

版权声明:本文为博主原创文章,未经博主允许不得转载。http://guozh.net/ https://blog.csdn.net/guozhaohui628/article/details/80335943

1 前言

如题所示,使用 spring+springmvc+mybatis 时报如下错误

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: No converter found for return value of type: class com.kstar.pojo.TbItem
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:981)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:860)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

No converter found for return value of type: class com.kstar.pojo.TbItem

2 解决

    @Autowired
    private ItemServiceImpl itemService;

    @RequestMapping(value = "/item/default",method = RequestMethod.GET)
    public @ResponseBody TbItem getDefaultTest(){
        TbItem tbItem =  itemService.queryItemById((long) 691300);
        return tbItem;
    }

查找了半天,才发现是没有配置 将对象转正 json 的 jar 。手动添加 jackson 依赖。

  <jackson.version>2.5.4</jackson.version>

  <!--jackson-->
  <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>

ok 解决!

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页