WebMvcConfigurer依赖
时间: 2023-10-12 14:07:00 浏览: 64
WebMvcConfigurer接口主要用于配置Spring MVC的行为。在Spring Boot 2.0之前,我们可以通过重写WebMvcConfigurerAdapter类的方法来添加自定义拦截器和消息转换器等。然而,在Spring Boot 2.0之后,WebMvcConfigurerAdapter类被标记为@Deprecated(弃用)。所以,为了实现自定义配置,官方推荐直接实现WebMvcConfigurer接口或继承WebMvcConfigurationSupport类。
如果我们想自定义消息转换器,可以使用ContentNegotiationConfigurer。ContentNegotiationConfigurer能够配置内容协商策略,例如选择哪种媒体类型(如JSON或XML)来作为响应的内容格式。我们可以通过自定义ContentNegotiationConfigurer来注册自己的消息转换器。
另外,如果我们对Spring默认的URL解析方式不满意,我们可以通过配置PathMatchConfigurer来进行自定义。PathMatchConfigurer可以配置路径匹配的规则,例如是否允许后缀模式、是否允许尾部斜杠等。如果不配置这些选项,Spring会使用默认配置。具体的配置方式可以参考RequestMappingHandlerMapping和ContentNegotiationStrategy配置。
综上所述,WebMvcConfigurer接口依赖于ContentNegotiationConfigurer和PathMatchConfigurer来实现自定义配置。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [SpringBoot中的WebMvcConfigurer配置接口的详解](https://blog.csdn.net/pan_junbiao/article/details/120039885)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [SpringMVC源码系列之自定义WebMvcConfigurer](https://blog.csdn.net/Crabime/article/details/98207697)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)