Spring Framework
WebMvcConfigurationSupport
WebMvcAutoConfiguration
Java
Spring Boot

Is it possible to extend WebMvcConfigurationSupport and use WebMvcAutoConfiguration?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

In Spring Boot, extending WebMvcConfigurationSupport is usually a signal that you want to take over MVC configuration yourself. That matters because Boot's MVC auto-configuration is designed to back off when you provide your own full MVC configuration. So the short answer is: not in the way most people hope.

Why Boot backs off

WebMvcAutoConfiguration exists to configure Spring MVC automatically with sensible defaults such as message converters, static resource handling, formatters, and argument resolvers. When you extend WebMvcConfigurationSupport, you are effectively providing a custom MVC setup, so Spring Boot assumes you want control and disables large parts of its automatic configuration.

That is why these two approaches do not compose naturally:

  • Boot auto-configures MVC for you
  • 'WebMvcConfigurationSupport lets you configure MVC yourself'

Trying to do both usually leads to missing defaults and confusing behavior.

Prefer WebMvcConfigurer for customization

If your real goal is "keep Boot defaults, but add a few customizations," implement WebMvcConfigurer instead of extending WebMvcConfigurationSupport.

java
1package com.example.demo;
2
3import org.springframework.context.annotation.Configuration;
4import org.springframework.web.servlet.config.annotation.CorsRegistry;
5import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
6
7@Configuration
8public class WebConfig implements WebMvcConfigurer {
9
10    @Override
11    public void addCorsMappings(CorsRegistry registry) {
12        registry.addMapping("/api/**")
13                .allowedOrigins("https://example.com")
14                .allowedMethods("GET", "POST");
15    }
16}

This approach keeps WebMvcAutoConfiguration active while still allowing you to customize the framework.

What happens if you extend WebMvcConfigurationSupport

If you do this:

java
1package com.example.demo;
2
3import org.springframework.context.annotation.Configuration;
4import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
5
6@Configuration
7public class MyMvcConfig extends WebMvcConfigurationSupport {
8}

you are stepping outside the usual Boot customization path. You may need to re-declare behavior that Boot would otherwise supply automatically, such as resource handlers or message converter defaults.

That is sometimes justified in advanced scenarios, but it should be an intentional decision, not a casual customization step.

For example, static resource handling may need to be reintroduced explicitly:

java
1@Override
2protected void addResourceHandlers(ResourceHandlerRegistry registry) {
3    registry.addResourceHandler("/**")
4            .addResourceLocations("classpath:/static/");
5}

That kind of extra work is exactly why WebMvcConfigurer is usually the better extension point for ordinary Boot applications.

When full control is actually appropriate

There are cases where extending WebMvcConfigurationSupport makes sense:

  • you are building a framework layer on top of Spring MVC
  • you need deep control over handler mappings or adapters
  • Boot's defaults actively conflict with the architecture you want

In those situations, it is better to accept that you are taking over MVC configuration. Do not expect Boot auto-configuration to keep filling in the gaps.

A practical mental model

Think of the choices like this:

  • 'WebMvcConfigurer: incremental customization on top of Boot defaults'
  • 'WebMvcConfigurationSupport: full ownership of MVC setup'

That distinction is more useful than memorizing implementation details. It helps you choose the right abstraction before the application becomes hard to reason about.

If you only need to add interceptors, CORS rules, view controllers, or formatters, WebMvcConfigurer is almost always the right answer.

Common Pitfalls

The biggest pitfall is extending WebMvcConfigurationSupport to make one small change and then being surprised when static resources, JSON handling, or other defaults behave differently. Boot did not "randomly break." You told it to step back.

Another issue is mixing advice from plain Spring MVC examples with Spring Boot applications. Many old tutorials assume you are wiring MVC manually. In Boot, the extension point is usually different.

It is also easy to overcorrect with @EnableWebMvc. That annotation similarly switches you into a more manual MVC mode and can disable useful Boot behavior.

Finally, if you truly need full control, document that decision clearly. Otherwise the next developer may spend hours trying to understand why ordinary Boot MVC conventions are not applying.

Summary

  • Extending WebMvcConfigurationSupport generally disables the normal Spring Boot MVC auto-configuration path.
  • Use WebMvcConfigurer when you want to keep Boot defaults and add small customizations.
  • Choose WebMvcConfigurationSupport only when you intentionally want full MVC control.
  • Do not expect Boot to keep supplying all defaults after you take over MVC configuration.
  • Treat the choice as an architectural one, not just a syntax preference.

Related reading
Course
Intermediate
27 lessons
14 hours
OOD Fundamentals

Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.