• 【springboot】之 解析@EnableWebMvc 、WebMvcConfigurationSupport和WebMvcConfigurationAdapter


    springboot默认格式化日期只需要在application文件中配置

    spring.jackson.date-format= yyyy-MM-dd HH:mm:ss
    spring.jackson.time-zone= GMT+8
    spring.jackson.locale= zh_CN

    但是,我在配置过程中发现日期格式依然是long类型,也就是日期格式没有生效

    经过查看代码发现,我的MvcConfig继承了WebMvcConfigurationSupport

    那么这个类到底做什么呢?导致application配置的json格式失效呢?

    如下:

    在spring-boot+spring mvc 的项目中,有些时候我们需要自己配置一些项目的设置,就会涉及到这三个,那么,他们之间有什么关系呢? 
    首先,@EnableWebMvc=WebMvcConfigurationSupport,使用了@EnableWebMvc注解等于扩展了WebMvcConfigurationSupport但是没有重写任何方法

    所以有以下几种使用方式:

    1. @EnableWebMvc+extends WebMvcConfigurerAdapter,在扩展的类中重写父类的方法即可,这种方式会屏蔽springboot的@EnableAutoConfiguration中的设置

    2. extends WebMvcConfigurationSupport,在扩展的类中重写父类的方法即可,这种方式会屏蔽springboot的@EnableAutoConfiguration中的设置

    3. extends WebMvcConfigurerAdapter,在扩展的类中重写父类的方法即可,这种方式依旧使用springboot的@EnableAutoConfiguration中的设置

    具体哪种方法适合,看个人对于项目的需求和要把控的程度

    在WebMvcConfigurationSupport(@EnableWebMvc)和@EnableAutoConfiguration这两种方式都有一些默认的设定 
    而WebMvcConfigurationAdapter则是一个abstract class

     改为

    @http://blog.csdn.net/pinebud55/article/details/53420481

  • 相关阅读:
    编程总结2
    编程总结1
    我的三位老师
    《秋季学期学习总结》
    CodeAction_beta02 斐波那契 (多维DP)
    bzoj3029 守卫者的挑战 (多维dp)
    修剪草坪 (单调队列)
    CF734F Anton and School (构造)
    CF359B Permutation (构造)
    CF989C A Mist of Florescence (构造)
  • 原文地址:https://www.cnblogs.com/gyjx2016/p/8494498.html
Copyright © 2020-2023  润新知