The documentation for @EnableWebMvc
describes three levels of customization for tailoring your configuration. You can:
- Use
@EnableWebMvc
on its own to import the standard configuration. - Use
@EnableWebMvc
with configuration classes that extendWebMvcConfigurerAdapter
; the subclasses will have their implemented methods called automatically to apply your changes to the standard configuration. - Don't use
@EnableWebMvc
, but instead make your configuration class extendWebMvcConfigurationSupport
to gain full control over your configuration.
However, what the documentation does not make clear is that if you go for option 3 it will not automatically apply the methods implemented in classes that extend WebMvcConfigurerAdapter
.
As others have said, we really need to see your full configuration, but if simply extending WebMvcConfigurationSupport
and removing @EnableWebMvc
breaks other parts of your configuration, my guess is that you are still using WebMvcConfigurerAdapter
somewhere else in your config.
If this is the case, you have two options:
- Rewrite all your configuration that uses
WebMvcConfigurerAdapter
and move the code into a single configuration class that extendsWebMvcConfigurationSupport
. - Extend
DelegatingWebMvcConfiguration
instead ofWebMvcConfigurationSupport
. This will give you all the standard configuration behaviour that you normally get when using@EnableWebMvc
but still allow you to override methods as required. Note that in any method you override, you'll also need to call the equivalent method insuper()
if you want to keep the default behaviour too.