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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM