前言 RestTemplate报错
报错
报错:org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [class java.lang.Object] and content type [text/html;charset=UTF-8]
原因
RestTemplate不支持Content-Type: text/html;charset=UTF-8类型的响应数据格式
解决问题
添加一个Content-Type: text/plan响应数据格式
1 2 3 4 RestTemplate restTemplate = new RestTemplate ();MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter ();mappingJackson2HttpMessageConverter.setSupportedMediaTypes(Arrays.asList(MediaType.TEXT_HTML, MediaType.TEXT_PLAIN)); restTemplate.getMessageConverters().add(mappingJackson2HttpMessageConverter);
报错
报错:java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/util/DefaultPrettyPrinter$Indenter
原因
没有添加Jackson依赖,或Spring依赖版本与Jackson依赖版本冲突
解决问题
1 2 3 4 5 6 7 8 9 10 11 12 <dependency > <groupId > com.fasterxml.jackson.core</groupId > <artifactId > jackson-core</artifactId > </dependency > <dependency > <groupId > com.fasterxml.jackson.core</groupId > <artifactId > jackson-databind</artifactId > </dependency > <dependency > <groupId > com.fasterxml.jackson.core</groupId > <artifactId > jackson-annotations</artifactId > <version > 2.9.0</version >
完成 参考文献 CSDN——TanaStudy CSDN——An_xiaowu CSDN——滕青山YYDS