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

时间:2019-12-12
本文章向大家介绍springboot 2.0 配置 spring.jackson.date-format 不生效,主要包括springboot 2.0 配置 spring.jackson.date-format 不生效使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

 

问题: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://www.cnblogs.com/kelelipeng/p/12028705.html