我是靠谱客的博主 超帅飞鸟,最近开发中收集的这篇文章主要介绍feign获取outstream_客户端通过Feign发起请求 服务端通过request取 json对象,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

importcom.fasterxml.jackson.databind.ObjectMapper;importcom.hexin.creditforce.configuration.feign.support.MapFormHttpMessageConverter;importfeign.Contract;importfeign.Logger;importfeign.Retryer;importfeign.codec.Decoder;importfeign.codec.Encoder;importfeign.form.spring.SpringFormEncoder;importorg.springframework.beans.factory.ObjectFactory;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.boot.autoconfigure.http.HttpMessageConverters;importorg.springframework.cloud.openfeign.support.ResponseEntityDecoder;importorg.springframework.cloud.openfeign.support.SpringDecoder;importorg.springframework.cloud.openfeign.support.SpringEncoder;importorg.springframework.context.annotation.Bean;importorg.springframework.context.annotation.Configuration;importorg.springframework.http.MediaType;importorg.springframework.http.converter.HttpMessageConverter;importorg.springframework.http.converter.json.MappingJackson2HttpMessageConverter;importjava.text.SimpleDateFormat;importjava.util.ArrayList;importjava.util.List;/*** feign config*/@Configurationpublic classFeignConfig {

@Autowiredprivate ObjectFactorymessageConverters;

@Bean

Logger.Level feignLoggerLevel() {returnLogger.Level.FULL;

}

@BeanpublicContract feignContract() {return newContract.Default();

}

@Bean

Retryer retryer() {returnRetryer.NEVER_RETRY;

}/*** form编码器,实现支持form表单提交*/@BeanpublicEncoder feignFormEncoder() {

MappingJackson2HttpMessageConverter jacksonConverter= newMappingJackson2HttpMessageConverter(customObjectMapper());

List> converters = new ArrayList<>();for (HttpMessageConverter>converter : messageConverters.getObject().getConverters()) {if (!(converter instanceofMappingJackson2HttpMessageConverter)) {

converters.add(converter);

}

}

converters.add(jacksonConverter);

converters.add(newMapFormHttpMessageConverter() );return new SpringFormEncoder(new SpringEncoder(() -> newHttpMessageConverters(converters)));

}

@BeanpublicDecoder feignDecoder() {

MappingJackson2HttpMessageConverter converter= newMappingJackson2HttpMessageConverter();

List supportedMediaTypes = new ArrayList<>( );

supportedMediaTypes.add( MediaType.ALL );

converter.setSupportedMediaTypes( supportedMediaTypes );

ObjectFactory objectFactory = () -> newHttpMessageConverters(converter);return new ResponseEntityDecoder(newSpringDecoder(objectFactory));

}privateObjectMapper customObjectMapper() {

ObjectMapper objectMapper= newObjectMapper();

objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));returnobjectMapper;

}

}

最后

以上就是超帅飞鸟为你收集整理的feign获取outstream_客户端通过Feign发起请求 服务端通过request取 json对象的全部内容,希望文章能够帮你解决feign获取outstream_客户端通过Feign发起请求 服务端通过request取 json对象所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(45)

评论列表共有 0 条评论

立即
投稿
返回
顶部