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区别

posted @ 2019-12-12 13:46  kelelipeng  阅读(2944)  评论(0编辑  收藏  举报