微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

关于Spring Boot消息转换器的困惑

如何解决关于Spring Boot消息转换器的困惑

我在将pdf下载到查看器时遇到问题。 错误指出没有转换器

org.springframework.http.converter.HttpMessageNotWritableException: No converter for [class com.....controller.rest.DocumentController$$Lambda$894/964587173] with preset Content-Type 'application/pdf'

我使用的是Spring Boot,我假设(并读到)这些转换器认情况下已启用

ByteArrayHttpMessageConverter – converts byte arrays
StringHttpMessageConverter – converts Strings
ResourceHttpMessageConverter – converts org.springframework.core.io.Resource for any type of octet stream
SourceHttpMessageConverter – converts javax.xml.transform.source
FormHttpMessageConverter – converts form data to/from a MultiValueMap<String,String>.
Jaxb2RootElementHttpMessageConverter – converts Java objects to/from XML (added only if JAXB2 is present on the classpath)
MappingJackson2HttpMessageConverter – converts JSON (added only if Jackson 2 is present on the classpath)
MappingJacksonHttpMessageConverter – converts JSON (added only if Jackson is present on the classpath)
AtomFeedHttpMessageConverter – converts Atom Feeds (added only if Rome is present on the classpath)
RSSChannelHttpMessageConverter – converts RSS Feeds (added only if Rome is present on the classpath)

当我检查执行器时,我只会看到String和Jackson消息转换器。

我确实有一个仅覆盖addViewControllers的WebMvcConfigurer

有人知道为什么不存在预设转换器吗?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。