SpringMVC序列化问题

x33g5p2x  于2022-03-02 转载在 Spring  
字(1.3k)|赞(0)|评价(0)|浏览(417)

问题描述

做练习的时候定义了一个练习的接口,正常情况下应该返回数据。

但是却出现了下面的异常,异常如下:

HTTP Status 500 - No converter found for return value of type: class com.domain.Result
type Exception report
message No converter found for return value of type: class com.domain.Result
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.springframework.http.converter.HttpMessageNotWritableException: No converter found for return value of type: class com.domain.Result
org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:226)
.......

解决方式

经过分析,问题是在于没有加载序列化的依赖,因为这个项目是基础的SSM项目,没有Springboot集成,所以出现这个问题的时候我有一丝懵逼,一度怀疑mvc的配置文件没有配置好。

具体的解决方式如下

<dependencies>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.9.6</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>2.9.6</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.9.6</version>
    </dependency>
</dependencies>

添加上jackson三件套就行了。

问题解决。

相关文章

微信公众号

最新文章

更多