1.SpringCloud集成Feign报错:feign.FeignException$NotFound: status 404 reading
解决:看看每个接口是否没有加上下文
2.no suitable HttpMessageConverter found for request type异常
解决:同下
//@Headers({"Content-Type: application/json;charset=UTF-8","Accept: application/json;charset=UTF-8"})
@RequestMapping(value = "/micro-mall-admin/interiorProxy/goods/admin/product/getProductList",method = RequestMethod.POST,consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Map proxy(@RequestBody QueryProductParam param);
3.no suitable HttpMessageConverter found for response type异常
解决:增加配置类:
@Configuration
@AutoConfigureAfter(JacksonAutoConfiguration.class)
public class FooClientConfig {
@Autowired
ObjectMapper objectMapper;
@Bean
public Decoder feignDecoder() {
HttpMessageConverter jacksonConverter = new MappingJackson2HttpMessageConverter(objectMapper());
List<MediaType> mediaTypes = new ArrayList<>();
//mediaTypes.add((MediaType) converter.getSupportedMediaTypes());
mediaTypes.add(MediaType.TEXT_PLAIN);
mediaTypes.add(new MediaType("text", "json", Charset.forName("UTF-8")));
mediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
mediaTypes.add(MediaType.TEXT_HTML);
mediaTypes.add(MediaType.APPLICATION_OCTET_STREAM);
mediaTypes.add(new MediaType("text", "plain", Charset.forName("UTF-8")));
((MappingJackson2HttpMessageConverter) jacksonConverter).setSupportedMediaTypes(mediaTypes);
ObjectFactory<HttpMessageConverters> objectFactory = () -> new HttpMessageConverters(jacksonConverter);
return new ResponseEntityDecoder(new SpringDecoder(objectFactory));
}
@Bean
public Encoder feignEncoder(){
HttpMessageConverter jacksonConverter = new MappingJackson2HttpMessageConverter(objectMapper());
List<MediaType> mediaTypes = new ArrayList<>();
mediaTypes.add(MediaType.TEXT_PLAIN);
mediaTypes.add(new MediaType("text", "json", Charset.forName("UTF-8")));
mediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
mediaTypes.add(MediaType.TEXT_HTML);
mediaTypes.add(MediaType.APPLICATION_OCTET_STREAM);
mediaTypes.add(new MediaType("text", "plain", Charset.forName("UTF-8")));
((MappingJackson2HttpMessageConverter) jacksonConverter).setSupportedMediaTypes(mediaTypes);
ObjectFactory<HttpMessageConverters> objectFactory = () -> new HttpMessageConverters(jacksonConverter);
return new SpringEncoder(objectFactory);
}
public ObjectMapper objectMapper() {
return Jackson2ObjectMapperBuilder.json()
.serializationInclusion(JsonInclude.Include.NON_NULL)
.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.timeZone(TimeZone.getTimeZone("Asia/Shanghai"))
.build()
.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);
}
public ObjectMapper customObjectMapper(){
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);
return objectMapper;
}
3.java.util.UnknownFormatConversionException: Conversion = '"' 或'\'
解决:@Test时不要用printf打印包含转义字符的json
//log.info(JSON.toJSONString(a));
System.out.printf(""+a.toString());
4.服务端返回{"resultCode":"500","resultMsg":"Content type 'text/plain;charset=UTF-8' not supported"}
解决:同2,在接口加上:
consumes = MediaType.APPLICATION_JSON_UTF8_VALUE