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区别
--------------------- 
作者:2yung 
来源:CSDN 
原文:https://blog.csdn.net/qq_30912043/article/details/80967352 
版权声明:本文为博主原创文章,转载请附上博文链接!

猜你喜欢

转载自my.oschina.net/u/2338224/blog/2396528