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

前言

如题所示,使用 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

解决

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

未经允许不得转载:老郭种树 » nested exception is java.lang.IllegalArgumentException: No converter found for return value of type

赞 (0)

评论

3+4=

能将我博客放入广告拦截白名单吗?

我尽量分享有用并且长期有用的内容,希望能帮到你,谢谢支持。