As written documentation https://docs.spring.io/spring-boot/docs/2.5.0/reference/htmlsingle/#howto.spring-mvc.switch-off-default-configuration.
The @EnableWebMvc actually switches off the autoconfigured capabilities. This is quite confusing when considering other annotations like @EnableEncryptableProperties, @EnableJpaAuditing, @EnableWebSecurity; which are annotations that turn on things.
Should not @EnableWebMvc be something like @WebMvcConfiguration or something like that?
Comment From: bclozel
The @EnableWebMvc
class predates Spring Boot and is part of Spring Framework.
The goal of this class is to enable the Spring MVC infrastructure in an application. Spring Boot chose to take the presence of this annotation (or the presence of a WebMvcConfigurationSupport
component) as sign that developers want to take full control over their web configuration.
Technically, Spring Boot could choose to have a different behavior in this case. Changing this behavior would require a major version.
On the Spring Framework side of things, the team could choose to favor the Spring Boot configuration model at the cost of making things harder for non Spring Boot users.
In both cases, this is not something we can fix at the Spring Boot level because this requires a important infrastructure change in Spring Framework. I'm closing this issue for now, but this doesn't mean that the Spring team will not consider that issue for future releases.
Thanks!