no suitable HttpMessageConverter found for response type

前端 未结 10 1776
深忆病人
深忆病人 2020-11-30 02:33

Using spring, with this code :

List> messageConverters = restTemplate.getMessageConverters();
for(HttpMessageConverter ht         


        
10条回答
  •  佛祖请我去吃肉
    2020-11-30 02:42

    From a Spring point of view, none of the HttpMessageConverter instances registered with the RestTemplate can convert text/html content to a ProductList object. The method of interest is HttpMessageConverter#canRead(Class, MediaType). The implementation for all of the above returns false, including Jaxb2RootElementHttpMessageConverter.

    Since no HttpMessageConverter can read your HTTP response, processing fails with an exception.

    If you can control the server response, modify it to set the Content-type to application/xml, text/xml, or something matching application/*+xml.

    If you don't control the server response, you'll need to write and register your own HttpMessageConverter (which can extend the Spring classes, see AbstractXmlHttpMessageConverter and its sub classes) that can read and convert text/html.

提交回复
热议问题