org.springframework.web.client.RestClientException: No HttpMessageConverter for java.util.LinkedHash

席安康
2023-12-01

org.springframework.web.client.RestClientException: No HttpMessageConverter for java.util.LinkedHashMap and content type “application/x-www-form-urlencoded;charset=UTF-8”

新建自定义转换器


import org.springframework.http.MediaType;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Susinl
 */
public class MyMappingJackson2HttpMessageConverter extends MappingJackson2HttpMessageConverter {
    public MyMappingJackson2HttpMessageConverter(){
        List<MediaType> mediaTypes = new ArrayList<>();
        mediaTypes.add(MediaType.ALL);
        setSupportedMediaTypes(mediaTypes);
    }
}

HttpClient.java中调用


Integer finalTimeOut = 300000;
CloseableHttpClient httpClient = HttpClientUtils.acceptsUntrustedCertsHttpClient();
HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
clientHttpRequestFactory.setConnectTimeout(60000);
clientHttpRequestFactory.setReadTimeout(finalTimeOut);
RestTemplate restTemplate = new RestTemplate(clientHttpRequestFactory);
restTemplate.getMessageConverters().add(new MyMappingJackson2HttpMessageConverter());

 类似资料:

相关阅读

相关文章

相关问答