2、@EnableWebMvc、WebMvcConfigurationSupport、WebMvcConfigurationAdapter @EnableWebMvc=WebMvcConfigurationSupport...,使用了@EnableWebMvc注解等于扩展了WebMvcConfigurationSupport但是没有重写任何方法 @EnableWebMvc+extends WebMvcConfigurationAdapter...,在扩展的类中重写父类的方法即可,这种方式会屏蔽springboot的WebMvcAutoConfiguration中的设置 @EnableWebMvc+extends WebMvcConfigurationSupport...只会使用@EnableWebMvc extends WebMvcConfigurationSupport,在扩展的类中重写父类的方法即可,这种方式会屏蔽springboot的@WebMvcAutoConfiguration...)说明,当没有WebMvcConfigurationSupport对应的bean时,才会使用该配置,所以当我们使用继承WebMvcConfigurationSupport的方式类扩展mvc时,原有的配置则无效
Spring Boot 自定义Spring MVC 配置: WebMvcConfigurationSupport package com.easy.springboot.demo_spring_mvc.mvc_config...import java.io.IOException @org.springframework.context.annotation.Configuration class WebMvcConfig : WebMvcConfigurationSupport
这里直接给出解决方案代码,这里支持FastJson和Jackson配置序列化的方式: @Configuration public class WebCatMvcConfiguration extends WebMvcConfigurationSupport...SerializerFeature.WriteNullBooleanAsFalse, SerializerFeature.WriteNullListAsEmpty); converters.add(converter); } } 最后我们也可以了解一下:WebMvcConfigurationSupport...类 下面是它的官方文档描述: public class WebMvcConfigurationSupport extends Object implements ApplicationContextAware
2.猜想验证 其实上面扯了这么多,还没说到关键点为什么重写了WebMvcConfigurationSupport会导致后台接收不了FormData?...果不其然,重写过WebMvcConfigurationSupport后,少了formParams这个属性,而formParams包含了我们想要的参数ids[]。...至于为什么重写WebMvcConfigurationSupport会丢失formParams?是不是毫无头绪?别急,我们先看下这个formParams是什么。...那至于为什么重写了WebMvcConfigurationSupport就会导致自动配置失效了呢?再看下WebMvcAutoConfiguration的头部注解描述。...@ConditionalOnMissingBean({WebMvcConfigurationSupport.class}),意思就是Spring容器中没有WebMvcConfigurationSupport
会覆盖的WebMvcConfigurationSupport WebMvcConfigurerAdapter被废弃了,那么我们还可以通过继承WebMvcConfigurationSupport来实现Spring...@ConditionalOnMissingBean({WebMvcConfigurationSupport.class})指定了,当Spring容器中不存在类型为WebMvcConfigurationSupport...DelegatingWebMvcConfiguration继承自WebMvcConfigurationSupport,而WebMvcConfigurationSupport为Spring MVC提供缺省配置...对的,就是上面我们讲到的继承了WebMvcConfigurationSupport的类。...汇总一下就是WebMvcConfigurationSupport有三种实现形式:第一,用户自定义WebMvcConfigurationSupport的实现类,此时会导致WebMvcAutoConfiguration
WebMvcConfigurationSupport 前面两个都好理解,还有一个 WebMvcConfigurationSupport ,这个又是干什么用的呢?...那么在这里我自定义 SpringMVC 配置的时候,就是通过继承 WebMvcConfigurationSupport 类来实现的。...在 WebMvcConfigurationSupport 类中,提供了用 Java 配置 SpringMVC 所需要的所有方法。我们来看一下这个方法的摘要: ?...在这里首先大家需要明确的是,WebMvcConfigurationSupport 类本身是没有问题的,我们自定义 SpringMVC 的配置是可以通过继承 WebMvcConfigurationSupport...换句话说,在纯 Java 配置的 SSM 中,如果你需要自定义 SpringMVC 配置,你离不开 WebMvcConfigurationSupport ,所以在这种情况下建议通过继承 WebMvcConfigurationSupport
) 表示如果spring容器中没有注入WebMvcConfigurationSupport类或者其子类实现时才注入改配置。...而WebMvcConfigurationSupport是mvc能力的主要配置类,一般将@EnableWebMvc加到应用启动类来开启mvc能力,或者使用另外一种高级实现,直接从此类扩展并根据需要重写方法...可以看到,EnableWebMvcConfiguration继承于WebMvcConfigurationSupport,所以前边提到@ConditionalOnMissingBean(WebMvcConfigurationSupport.class...)目的就是如果用户自定义了WebMvcConfigurationSupport或者其子类实现,那么就放弃springboot默认实现这一套。...或者其子类 我们直接继承WebMvcConfigurationSupport类 @Configuration public class CustomWebMvcConfigurationSupport
但是如果你想要自己配置一些项目的设置,你可以在@Configuration注解的配置类上增加@EnableWebMvc或者继承WebMvcConfigurationSupport和WebMvcConfigurationAdapter...正文: 首先解析@EnableWebMvc 、WebMvcConfigurationSupport和WebMvcConfigurerAdapter # 在spring-boot+spring mvc...首先,@EnableWebMvc=WebMvcConfigurationSupport,使用了@EnableWebMvc注解等于扩展了WebMvcConfigurationSupport但是没有重写任何方法...extends WebMvcConfigurerAdapter,在扩展的类中重写父类的方法即可,这种方式会屏蔽springboot的@EnableAutoConfiguration中的设置 extends WebMvcConfigurationSupport...WebMvcConfigurerAdapter,在扩展的类中重写父类的方法即可,这种方式依旧使用springboot的@EnableAutoConfiguration中的设置 具体哪种方法适合,看个人对于项目的需求和要把控的程度,在WebMvcConfigurationSupport
DelegatingWebMvcConfiguration.class @Configuration(proxyBeanMethods = false) public class DelegatingWebMvcConfiguration extends WebMvcConfigurationSupport...{ … } public class WebMvcConfigurationSupport implements ApplicationContextAware, ServletContextAware...Qualifier("mvcResourceUrlProvider") ResourceUrlProvider resourceUrlProvider) { ... } ... } 其中 实现类 WebMvcConfigurationSupport.java
这里大家注意,看看自己的代码有没有因为添加拦截器而创建了一个配置类,该类继承了WebMvcConfigurationSupport,就是他!...以前是用 WebMvcConfigurerAdapter,springboot 2.0 建议使用 WebMvcConfigurationSupport 。...但是在添加拦截器并继承 WebMvcConfigurationSupport后会覆盖@EnableAutoConfiguration关于WebMvcAutoConfiguration的配置!...可以采用另外一种方式,在你继承WebMvcConfigurationSupport的子类中添加日期转换的bean @Configuration public class Configurer extends...WebMvcConfigurationSupport{ @Autowired HttpInterceptor httpInterceptor; //定义时间格式转换器
如上图所示,这个WebAutoConfiguration会在类级别注解扫描的时候被扫描到,但是它和webmvcConfigurationSupport是不兼容的,所以这个类只对WebMvcConfigurer...---- 那么如果我们直接继承WebMvcConfigurationSupport会怎样? 首先我们要知道我们的AutoWebMvcConfiguration是不会起作用了。...但是我们发现WebMvcConfigurationSupport中有很多@Bean的注解,意思就是说只要我们的自定义类上具有@Configuration注解就可以独善其身了。...毕竟WebMvcConfigurationSupport里包含了很多组件。直接用就好了。当然如果我们需要自定义的话就得重写,当然必须要对一些组件特别了解,否则可能会出问题。...第二种方式是继承WebMvcConfigurationSupport,因为WebMvcConfigurationSupport包含了很多@Bean的对Spring注册,所以可以直接使用,但对于比较复杂的方法重写上需要足够的了解才可以
在这里需要声明一个前提:**配置类上没有标注@EnableWebMvc并且没有任何一个配置类继承了WebMvcConfigurationSupport**。至于具体原因,下文会详细解释。...{} 明白了,@EnableWebMvc这个注解实际上就是导入了一个WebMvcConfigurationSupport子类型的配置类而已。...而WEB模块的自动配置类有这么一行注解@ConditionalOnMissingBean(WebMvcConfigurationSupport.class),源码如下: @Configuration(proxyBeanMethods...一切都已经揭晓了,@EnableWebMvc导入了一个WebMvcConfigurationSupport类型的配置类,导致了自动配置类WebMvcAutoConfiguration标注的@@ConditionalOnMissingBean...(WebMvcConfigurationSupport.class)判断为false了,从而自动配置类失效了。
2、写接口的时候使用log.info打印数据 3、SpringMVC WebMvcConfigurationSupport类作用 WebMvcConfigurationSupport类是Spring Boot...通过继承WebMvcConfigurationSupport类并重写相应的方法,可以实现对Spring Boot Web MVC框架的配置定制。
主要是因为继承了WebMvcConfigurationSupport类,这个类有很多可以自定义的方法,使用起来很方便。...这是因为在WebMvcConfigurationSupport类中,extendMessageConverters方法被调用来扩展默认的消息转换器列表。...那我们来解决第一个问题:为什么继承WebMvcConfigurationSupport后,要重写extendMessageConverters方法?...现在我们知道为什么在继承WebMvcConfigurationSupport后要重写extendMessageConverters了。...我们知道,当我们继承WebMvcConfigurationSupport类后,会导致自动注入的mvc配置失效。
我注意到在自动配置类WebMvcAutoConfiguration上面有一句注解@ConditionalOnMissingBean({WebMvcConfigurationSupport.class})...我明白了,之前在做登录拦截的时候,编写了WebMvcConfiguration,该类继承了WebMvcConfigurationSupport,所以自己编写的WebMvcConfiguration类不能让...WebMvcConfiguration中配置OrderedHiddenHttpMethodFilter @Configuration public class WebMvcConfiguration extends WebMvcConfigurationSupport
basePackageClasses = Application.class, useDefaultFilters = true) public class ServletContextConfig extends WebMvcConfigurationSupport...默认为/**,当配置hello.config.ServletContextConfig后此处配置失效 mvc: static-path-pattern: /static/** 但当我们继承了WebMvcConfigurationSupport...org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport...basePackageClasses = Application.class, useDefaultFilters = true) public class ServletContextConfig extends WebMvcConfigurationSupport...application.environment"; static final private String PROPERTY_DEFAULT_ENV = "dev"; /** * 发现如果继承了WebMvcConfigurationSupport
WebMvcConfigurationSupport声明了以支撑 Spring MVC 功能流转的一些 Bean,比如 HandlerMapping、HandlerAdapter、HandlerExceptionResolver...在这些 Bean 的声明逻辑中,往往涉及对若干 protected 方法的调用,这些 protected 方法自然是为子类预留的,方便子类去做一些个性化拓展,官方从 WebMvcConfigurationSupport...非 WebMvcConfigurationSupport 子类莫属,这个子类就是DelegatingWebMvcConfiguration: @Configuration(proxyBeanMethods...= false) public class DelegatingWebMvcConfiguration extends WebMvcConfigurationSupport { private
会导致所有自动配置全部失效 @EnableWebMvc导入了一个DelegatringWebMvcConfiguration类 图片 DelegatringWebMvcConfiguration又继承了WebMvcConfigurationSupport...图片 再回来看WebMvcAutoConfiguration自动配置类上标注了条件注解 @ConditionalOnMissingBean(WebMvcConfigurationSupport.class...)也就是说,只有在WebMvcConfigurationSupport不在容器中时才会将自动配置类导入容器中。...@EnableWebMvc注解往容器中导入了一个WebMvcConfigurationSupport的子类DelegatringWebMvcConfiguration,这就会导致WebMvcAutoConfiguration...不会导入到容器中,当然也就无法发挥自动配置的作用了 图片 而@EnableWebMvc注解导入的WebMvcConfigurationSupport的子类DelegatringWebMvcConfiguration
解决方案 第一种,添加配置类 继承 WebMvcConfigurationSupport 重写 addResourceHandlers 方法。...org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport...web 配置类 * * @author MoBaiJun 2022/5/13 11:25 */ @Configuration public class WebMvcConfig extends WebMvcConfigurationSupport...documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException * 发现如果继承了 WebMvcConfigurationSupport
领取专属 10元无门槛券
手把手带您无忧上云