問題: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區別