springboot 2.0 配置 spring.jackson.date-format 不生效

本文分析了在SpringBoot应用中,由于使用WebMvcConfigurationSupport导致application.properties中的date-format配置失效的问题。深入探讨了问题原因,并提供了解决方案,即通过实现WebMvcConfigurer接口来避免配置被覆盖。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题:application.properties中的如下配置不生效,返回时间戳

spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
原因分析:

       拦截器继承的 WebMvcConfigurationSupport !

       以前是用 WebMvcConfigurerAdapter ,springboot 2.0 建议使用 WebMvcConfigurationSupport 。但是在添加拦截器并继承 WebMvcConfigurationSupport 后会覆盖@EnableAutoConfiguration关于WebMvcAutoConfiguration的配置!从而导致所有的Date返回都变成时间戳!

解决方法:

       实现 WebMvcConfigurer。

       将:

extends WebMvcConfigurationSupport
       改为:

implements WebMvcConfigurer
引用:

SpringBoot拦截器WebMvcConfigurationSupport导致date-format失效

@EnableWebMvc,WebMvcConfigurationSupport,WebMvcConfigurer和WebMvcConfigurationAdapter区别
 

转载于:https://my.oschina.net/u/200350/blog/2989968

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值