概述
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对象所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复