Skip to content

Clarify the effect of using @EnableWebMvc #36506

Closed
@sandipchitale

Description

@sandipchitale

The following line:

https://github.com/spring-projects/spring-boot/blob/07a7ff473b6e97db6f00eb62f4f8beb2fb8da73b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/web/servlet.adoc?plain=1#L45C1-L45C1

does say (specifically but without @EnableWebMvc) :

If you want to keep those Spring Boot MVC customizations and make more {spring-framework-docs}/web.html#mvc[MVC customizations] (interceptors, formatters, view controllers, and other features), you can add your own @Configuration class of type WebMvcConfigurer but without @EnableWebMvc.

IMO this should be made explicitly crystal clear as to why? Something along the lines of:

If you have a configuration with @EnableWebMvc in your Springboot application that basically instantiates the Spring WebMVC bean DelegatingWebMvcConfiguration which extends WebMvcConfigurationSupport and that trips/fails the @ConditionalOnMissingBean(WebMvcConfigurationSupport.class) annotation on WebMvcAutoConfiguration and it backs off.

I think many users read the section:

Enable MVC Configuration

which seems to tell them to turn on @EnableWebMvc.

I think @EnableWebMvc disabling the Spring Boots MVC autoconfiguration comes across as a confusing double negative to new users.

Once one understands what is going on it makes sense, but I got tripped by it and have seen issues filed and many SO entries.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions