EnableWebMvc vs WebMvcConfigurationSupport
-
spring doc解釋spring
-
WebMvcConfigurationSupport: This is the main class providing the configuration behind the MVC Java config. It is typically imported by adding @EnableWebMvc to an application @Configuration classapp
-
@EnableWebMvcide
- To customize the imported configuration, implement the interface WebMvcConfigurer and override individual methods
- If WebMvcConfigurer does not expose some more advanced setting that needs to be configured consider removing the @EnableWebMvc annotation and extending directly from WebMvcConfigurationSupport or DelegatingWebMvcConfiguration
- // 使用@EnableWebMvc註解會覆蓋自定義的WebMvcConfigurationSupport配置
-
-
兩者的共同點spa
- 都是爲了配置MVC
-
兩者的區別繼承
- @EnableWebMvc註解的實現是基於WebMvcConfigurationSupport,詳見@EnableWebMvc的doc
- 三種應用形式只能選其一,若是自定義的WebMvcConfigurationSupport與@EnableWebMvc共同存在,則自定義的WebMvcConfigurationSupport配置會被覆蓋
- 自定義(高級模式): 繼承WebMvcConfigurationSupport
- 自定義(極簡模式): @EnableWebMvc註解+實現WebMvcConfigurer接口
- 默認模式: 使用@EnableWebMvc註解