2
在传统的Spring MVC的,我可以扩展WebMvcConfigurationSupport
并执行以下操作:什么是Spring Boot中的WebMvcConfigurationSupport替换项?
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.favorPathExtension(false).
favorParameter(true).
defaultContentType(MediaType.APPLICATION_JSON).
mediaType("xml", MediaType.APPLICATION_XML);
}
如何做到这一点。在Spring应用程序启动?我的理解是,添加WebMvcConfigurationSupport
和@EnableWebMvc
将禁用Spring Boot WebMvc自动配置,这是我不想要的。在auto configuration and Spring MVC
你说的没错,我知道,但我目前正在扩展类不是'WebMvcConfigurerAdapter'但'WebMvcConfigurationSupport'。后者提供前者不支持的配置选项。 –
我不认为有可能使用Spring Boot的WebMvcAutoConfiguration的任何部分并提供您自己的WebMvcConfigurationSupport,因为如果没有WebMvcConfigurationSupport,Spring Boot将仅自动配置。我认为使用Spring Boot的优点之一就是自动配置。我会尝试使用WebMvcConfigurerAdapter,对于不支持的选项,使用某种BeanPostProcessor来手动对其进行自定义。 – ikumen
我会试试。既然你的答案不是我正在寻找的,我现在不接受它,但我会赞成它。如果这个解决了,我会稍后接受你的答案。 –