SpringCloud Feign传递Date参数时差问题的解决方案

Feign源码解析之代理类的处理逻辑 FeignClient源码解析之注入IOC容器 FeignClient源码解析之生成jdk动态代理 上面两篇文章分析了在springboot中feign是如何注入IOC容器并生成jdk动态代理类的,下面我们将着重分析一下feign的代理类的处理逻辑,看一看代理类是如何将接口里的方法转化成http请求的。 之前的文章有提到,在通过FeignClientFactoryBean的getObject方法生... 阅读详情
AI摘要

本文解决Feign传输Date类型参数存在的误差问题。通过自定义类型转换器实现Date与String的双向转换,确保时间准确无误。

1、前言

      使用SpringCloud的朋友,再试传递Date参数的时候,有没有遇到时间差的问题呢。代码如下:

 @GetMapping("/testDate")
 void testDate(@RequestParam("date") Date date);

关于时间差的问题我们又该使用什么方式去处理呢?

2、原因

     先看一个简单的例子:

第一条打印的结果是正确的,但是当通过d2的转化就会有时差。

首先先说一下为什么会这样测试呢。因为数据Date在数据传输的工程中就会调用toString()的方法。所以Feign调用的时候也就会出现这样的问题。

具体原因是啥呢?

我们看下Date的parse()方法:

parse()方法上有这样一段注释:

 

大致意思就是:parse()方法是使用会根据时区的偏移量来解析的,如果不指定的时区的话,默认使用本地时间,也就是U.S时区的时间。

通过打印的结果可知:传入的string数据数是CTS标识的日期。

CTS代表的时区其实有四个(Central Standard Time (USA) UT-6:00、Central Standard Time (Australia) UT+9:30、China Standard Time UT+8:00、Cuba Standard Time UT-4:00),同时表示美国,澳大利亚,中国,古巴四个国家的标准时间。

可以看到CST会被当作美国中部的时区Central Standard Time,即JVM认为你传入的时间是美国中部的时间,而当date2调用toString方法的时候,它会检测到系统的时区是中国,就会自动加14个小时(东八区与西六区的时差)

解决方案也很简单,从注释上可以看到。parse()已经过时,替代方法是DateFormat.parse().

3、Feign 参数的处理

      处理是方法有多种。

  •       不传递Date参数,直接传递long类型的时间戳,接收端再去转化。
  •       直接使用DateFormat直接将时间转化成【yyyy-MM-dd HH:mm:ss】,当成字符串传输,接  收端自行解析。
  •       框架处理,自定义以类型转化器

4、框架的处理

4.1 定义类型转化器

@Component
public class DateFormatRegister implements FeignFormatterRegistrar {

	public DateFormatRegister(){
	}

	@Override
	public void registerFormatters(FormatterRegistry registry) {
		registry.addConverter(Date.class, String.class, new Date2StringConverter());
	}
	
	private class Date2StringConverter implements Converter<Date,String>{
		@Override
		public String convert(Date source) {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			return sdf.format(source);
		}
	}
}

这种定方式,是单向的。只能将Date转化成String。接收端需要与之对应的解析转化器。

解析转化器的配置:

@Configuration
public class String2DateConfig {

    @Autowired
    private RequestMappingHandlerAdapter handlerAdapter;

    /*
     *  增加字符串转日期的功能
     */
    @PostConstruct
    public void initEditableValidation() {
        ConfigurableWebBindingInitializer initializer = (ConfigurableWebBindingInitializer) handlerAdapter
                .getWebBindingInitializer();
        if (initializer.getConversionService() != null) {
            GenericConversionService genericConversionService = (GenericConversionService) initializer
                    .getConversionService();
            genericConversionService.addConverter(String.class, Date.class, new String2DateConverter());
        }
    }

    private class String2DateConverter implements Converter<String, Date> {
        @Override
        public Date convert(String source) {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            try {
                return simpleDateFormat.parse(source);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            return null;
        }
    }
}

这两种必须都要配置才能做到传输和接受的正确性。

缺少任何一个都会报错:String 不能解析成Date或者Date不能转化成String。

这种配置代码量有点大,作为一个有追求的coder,看起来的还是有点难受的。下来介绍终极解决方案。

4.2 终极解决方案

能不能通过一个【DateFormatRegister】完成配置呢。当然可以。

@Configuration
public class FeignDateFormatRegister implements FeignFormatterRegistrar {
    @Override
    public void registerFormatters(FormatterRegistry registry) {
        registry.addFormatter(dateFormatter());
    }

    @Bean
    public DateFormatter dateFormatter(){
        return new DateFormatter("yyyy-MM-dd HH:mm:ss");
    }

}

搞定。看起来果然简单不少。看些舒服多了。DateFormatter为什么会加注入到Spring容器中呢。因为这个DateFormatter是需要复用的,放在容器中可以一直使用。所以需要Spring的管理。否则配置不会生效。

5、后记

        在使用中会发现 FeignFormatterRegistrar 是针对Feign接口传输定制的Formatter,该Formatter是针对单个参数使用的。JDK8中也可以定制LocalDateTime等类型。

        Feign接口调用会使用Http请求,Get请求会拼接参数发起Http请求。接受参数时,使用FeignFormatterRegistrar 是接收不到参数。需要在 WebMvcConfigurer 注册Formatter,也可以使用@InitBind注解。

参考文档:

SpringCloud Feign 传输Date类型参数存在误差的问题_m0_67621429的博客-CSDN博客

SpringCloud Feign 传输Date类型参数存在误差 最近在项目开发过程中,前端传递过来的时间(Date类型)在A模块是正确的,然后A模块调用B模块将时间(Date类型)作为参数传过去,然后B模块接收到的时间有误差,天数会多一天,小时少10小时,这应该是SpringCloud Feign组件造成的问题,我这里的解决办法是在A模块调用之前先将时间(Date类型)转为String类型,B模块接收到A模块的参数后将时间由String类型再转为Date类型就... 阅读详情

相关推荐

解决Spring Boot和Feign中使用Java 8时间日期API(LocalDate等)的序列化问题

主要介绍了解决Spring Boot和Feign中使用Java 8时间日期API(LocalDate等)的序列化问题,需要的朋友可以参考下

关于feign接口调用时的Date类型数据传参问题

feign接口调用时的Date类型数据变更问题

admin_Object的博客 1100

vivado下ECO操作-不重新综合实现修改属性并生成.bit

ECO即engineer change order,即工程变更指令,可以对设计做局部小改动并只对改动部分重新布局布线并生成.bit。在一个工程动辄编译几个小时情况下,可以在调试中节省大量时间。比如我们在调试中,需要改变时钟占空比或者相位,需要改变寄存器初值等等,此时用ECO暂时改动,待验证后在重新编译无疑是最有效率的方法。 实现ECO通常有两种方式,一是通过vivado界面完成,另一种方法就是tcl脚本。所有的ECO操作都可以通过tcl操作完成,有的操作用vivado界面无法完成,只能通过tcl。以下主要

4675

SpringCloud Feign 传参问题及传输Date类型参数的时差

1.多参数表单类型传输 @PostMapping("/service/system/advertiser/save") Response&lt;Boolean&gt; saveAdvertiser(@RequestParam("username") String username, @RequestParam(...

Zany540817349的博客 1万+

Blender到Unreal Engine高效资产迁移:Datasmith插件工作流详解

在3D内容创作与实时渲染领域,数字资产的无损迁移是连接创意设计与最终呈现的关键环节。其核心原理在于通过高保真的数据转换管道,替代传统离散的导出-导入流程,从而保留完整的场景层级、材质属性和关联信息。这项技术的核心价值在于极大提升了跨平台工作流的效率与数据保真度,减少了因格式转换导致的信息丢失和调试成本。它广泛应用于建筑可视化、产品设计、影视预演和游戏开发等场景,使艺术家能在专业DCC工具中专注创作,并一键同步至实时引擎进行交互式渲染与逻辑构建。本文聚焦于实现这一流程的**Datasmith**插件,并深入解

weixin_34110970的博客 280

从零到一:Zephyr RTOS 在 STM32F4 上的移植与实战(含设备树配置详解)

本文详细介绍了如何从零开始将Zephyr RTOS移植到STM32F4开发板,涵盖开发环境搭建、硬件抽象层分析、设备树配置及系统裁剪等关键步骤。通过实战案例,帮助开发者掌握Zephyr RTOS在嵌入式设备中的应用,提升物联网边缘计算设备的开发效率。

weixin_26976635的博客 601

SpringCloud Feign 传输Date类型参数存在误差的问题

Feign传输Date类型参数存在误差 最近在项目开发过程中,前端传递过来的时间(Date类型)在A模块是正确的,然后A模块调用B模块将时间(Date类型)作为参数传过去,然后B模块接收到的时间有误差,天数会多一天,小时少10小时,这应该是SpringCloud Feign组件造成的问题 我这里的解决办法是在A模块调用之前先将时间(Date类型)转为String类型,B模块接收到A模块的参数后将时间由String类型再转为Date类型就可以了 时间转换代码如下 /** * 日期格式化为字符串 * * @pa

m0_67621429的博客 1330

高精度计算Π的值(C语言)

题目要求 限制使用双向链表作存储结构,请根据用户输入的一个整数(该整数表示精确到小数点后的位数,可能要求精确到小数点后500位),高精度计算PI值。可以利用反三角函数幂级展开式来进行计算。 输入5 输出3.14159 思路分析 反三角函数幂级展开式 由公式可以看出,只要计算出来每一个R(n)的值再相加取二倍就可以得到Π的值。 经过推算,要是令R(1)=2,只需要将每个R(n),相加即可。 因...

weixin_46251155的博客 8036

Feign发送Get请求时,采用POJO对象传递参数的最终解决方案 Request method 'POST' not supported (附带其余好几个坑)

【小家Spring】Feign发送Get请求时,采用POJO对象传递参数的最终解决方案 Request method 'POST' not supported (附带其余好几个坑) //注意!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //试了一下,这篇引用的<dependency> <groupId>co...

f45056231p的博客 1649

GEO的工作原理,以及GEO会催生出更多的爬虫岗位吗?

摘要: GEO(生成式引擎优化)是提升内容在AI搜索(如ChatGPT、Perplexity等)中引用率的新策略,核心在于优化内容的可抓取性、语义清晰度、权威性。与传统SEO不同,GEO聚焦AI的引用逻辑,需通过爬虫监控AI回答、逆向分析引用源特征(如结构化数据、权威背书),并构建自动化工具优化内容。爬虫工程师需转型为“AI可见性基础设施构建者”,重点关注高权威站点、知识库及官方信息源,同时确保技术可抓取性(如放行AI爬虫UA)。GEO的核心是从“排名”转向“被AI引用”,强调实体识别与动态对话适配。

数据知道的博客 4656

实例详解C++程序的五大内存分区

本文详细讲述C++程序在运行时的5大内存分区。 下面使用日常开发中的编程实例,详细介绍一下这5个分区,以便大家能更深刻的理解这5大内存分区。 1、栈内存区 栈内存区是我们用的最多的分区,只要有函数的地方都会使用到这个分区。栈分区是用来存放函数参数及函数局部变量值的内存区,是由编译器在编译时自动分配和释放的。 函数中的参数与函数中的局部变量占用的内存是代码执行到函数(进入函数)是分配的,在............

dvlinker的技术专栏 1万+

spring cloude 使用fegin远程调用接口返回了linkedHashMap的问题

作者情况描述: 最近在使用微服务进行服务之间的调用,通过fegin client调用时出现的问题 接口服务方返回参数: 接口层封装返回的对象 Result 实现层返回的对象 DeviceVo 接口调用方放回值类型:Result 调用后返回的对象:Result,注意此时的data对象为LinkedHashMap 并显示报错信息: [java.lang.ClassCastExcept...

Mou_O的博客 3661

姿态传感器/陀螺仪之ICM-42670-P应用原理图设计

ICM-42670-P采用LGA-14封装,尺寸为2.5x3x0.76毫米,工作电压范围为1.71V至3.6V,支持I3CSM、I2C和SPI串行通信接口。其设计目标是提供高精度、低功耗和小型化的解决方案,以满足消费类和工业应用的需求。ICM-42670-P是一款由TDK InvenSense推出的高性能六轴MEMS运动追踪传感器,集成了3轴陀螺仪和3轴加速度计,适用于多种应用场景,包括可穿戴设备、游戏控制器、无人机、AR/VR设备等。

corlin6688的博客 1218

feign 的 Date 类型的日期如何处理?

1、feign 版本 采用spring boot 1.5.3 1.1 get 请求 ,例如: @FeignClient(value = "server1", url = "http://localhost:8090") public interface FeignClientTest { @GetMapping("test6") String test6(@RequestParam...

hysxchina的博客 5728

MATLAB 基于 Baker 映射和 Logistic 混沌序列的图像加解密实现

图像加密是信息安全领域的重要研究方向,在数字版权保护、隐私保护等领域有着广泛应用。本文将介绍基于 MATLAB 的 Baker 映射和 Logistic 混沌序列的图像加解密算法,该算法利用混沌系统的初值敏感性和伪随机性,能够有效地对图像进行加密和解密。基于 Baker 映射和 Logistic 混沌序列的图像加解密算法是一种有效的方法,可以应用于数字版权保护、隐私保护等领域。MATLAB 提供了强大的工具和函数,可以方便地实现该算法。

走向CTO的路上... 945

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

feign 接口传参Date,调用方解析不了,日期为CST格式字符串

openfeign接口传参Date

a15093142309的博客 1103

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

【已解决】OpenFegin调用时LocalDate时间转换异常处理

【代码】【已解决】OpenFegin调用时LocalDate时间转换异常处理。

qq_42923605的博客 3049

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Feign实战配置与详细解析

Feign是一种声明式、模板化的HTTP客户端。在Spring Cloud中使用Feign, 我们可以做到使用HTTP请求远程服务时能与调用本地方法一样的编码体验,开发者完全感知不到这是远程方法,更感知不到这是个HTTP请求,类似于Dubbo的RPC; 在Spring Cloud环境下,Fe...

chengjiaoti5842的博客 862

通过feign传输localdatetime字段的时候丢失精度的问题

通过feign传输localdatetime字段的时候丢失精度的问题通过feign传输localdatetime字段的时候丢失精度的问题总结 通过feign传输localdatetime字段的时候丢失精度的问题 场景:A服务调用到B服务操作,通过Feign需要传递string参数和localdatetime参数过去,在测试的时候发现时间始终对不上。通过dubug后发现A服务传递的localdatetime参数正常,但是B服务接收到localdatetime参数缺失了"秒" 请求侧A服务原代码: @R

mjm_1251162714的博客 1902

Spring Cloud Feign的用法

1.feign是什么? 官方的说法:Feign是一个声明式的Web服务客户端。这使得Web服务客户端的写入更加方便 要使用Feign创建一个界面并对其进行注释。它具有可插入注释支持,包括Feign注释和JAX-RS注释。Feign还支持可插拔编码器和解码器。Spring Cloud增加了对Spring MVC注释的支持,并使用Spring Web中默认使用的HttpMessageConverter...

weixin_41281770的博客 401

关于feign接口调用时的date类型的传参问题

先说结论:在feign接口调用时使用表单形式(@RequestParam)传date类型会发生时间精度错乱,在8时区会多14个小时。 使用json格式(@RequestBody)传date类型不会发生这种情况。 表单形式我的解决办法是:在对外暴露的feign接口中使用字符串类型(String date)来接收日期,在真正feign调用的controller服务中使用@DateTimeForma...

You_are_my_Mr_Right的博客 6177

SpringCloud 基础教程(七)-Feign声明式服务调用

  我的博客:兰陵笑笑生,欢迎浏览博客!  上一章 SpringCloud基础教程(六)-负载均衡Ribbon当中,我们介绍了Ribbon在微服务中是如何做到负载均衡的,本期我们将在此基础上使用Fegin更加简化的实现服务间的调用。 前言  什么是Fegin,在解释之前,我们先梳理一下我们之前学习到的,在微服模式下,解决服务间的调用可以通过Grpc、HttpClie...

qq_39922158的博客 791

【feign,get传递Date日期类型参数,序列化失败,序列化默认时间格式,非标准时间格式】

使用feign接口来进行get请求, 因为参数比较多,所有使用了对象来接收参数, 因为feign会自动将对象参数的请求转换post请求,所以使用@SpringQueryMap注解,将参数自动拼接在url上, 在传递date时间类型时,提示序列化失败问题, 原因是feign在将对象参数转换为url时,直接使用tostring默认转换方法, date默认转换这种,Wed Apr 26 10:16:06 CST 2023,默认时间格式 在反序列化时失败,

weixin_44446230的博客 1693

openFeign,我的时间呢?

最近公司的项目需要从单体架构变为微服务架构,于是乎对项目的代码进行了重构,在处理服务之间的调用问题时,我们使用了openFeign组件,开发的时候都很顺利,但是当传递的参数使用的是Date类型的时候,却出现了意想不到的问题。

玄武后端技术栈 461
上一篇: 优雅的处理参数校验以及异常
下一篇: 基于Feign接口的全链路拦截器
智_永无止境
博客等级 码龄10年 803粉丝 416原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

智_永无止境

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址