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