guozhaohui628

-------胜利女神在微笑-----

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

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 解决!

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/guozhaohui628/article/details/80335943
个人分类: 我的错就是你的错
想对作者说点什么? 我来说一句

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

不良信息举报

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

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭