gpt4 book ai didi

java - 是否可以扩展 WebMvcConfigurationSupport 并使用 WebMvcAutoConfiguration?

转载 作者:IT老高 更新时间:2023-10-28 13:58:36 25 4
gpt4 key购买 nike

我还需要扩展 WebMvcConfigurationSupport 类修改两件事:

@Configuration
public class WebConfig extends WebMvcConfigurationSupport {
@Override
public RequestMappingHandlerMapping requestMappingHandlerMapping() {
RequestMappingHandlerMapping handlerMapping = super.requestMappingHandlerMapping();
handlerMapping.setRemoveSemicolonContent(false);
handlerMapping.setOrder(1);
return handlerMapping;
}
}

我喜欢从 WebMvcAutoConfiguration 类注册的默认值,但由于类上的条件注释,当我扩展 WebMvcConfigurationSupport 类时,它会阻止自动配置发生。

@Configuration
@ConditionalOnWebApplication
@ConditionalOnClass({ Servlet.class, DispatcherServlet.class,
WebMvcConfigurerAdapter.class })
@ConditionalOnMissingBean(WebMvcConfigurationSupport.class)
@Order(Ordered.HIGHEST_PRECEDENCE + 10)
@AutoConfigureAfter(DispatcherServletAutoConfiguration.class)
public class WebMvcAutoConfiguration {...}

是否可以加载 WebMvcAutoConfiguration 类而无需复制/粘贴该类中的大部分代码?

或者是否可以从其他地方调用 RequestMappingHandlerMapping setOrder() 和 setRemoveSemicolonContent() 以便我可以使用 @EnableWebMvc 注释并让自动配置类运行而没有任何问题?

提前致谢!

最佳答案

DelegatingWebMvcConfiguration 而不是 WebMvcConfigurationSupport 扩展,它不会阻止自动配置发生:

@Configuration
public class WebConfig extends DelegatingWebMvcConfiguration {
@Override
public RequestMappingHandlerMapping requestMappingHandlerMapping() {
RequestMappingHandlerMapping handlerMapping = super.requestMappingHandlerMapping();
handlerMapping.setRemoveSemicolonContent(false);
handlerMapping.setOrder(1);
return handlerMapping;
}
}

关于java - 是否可以扩展 WebMvcConfigurationSupport 并使用 WebMvcAutoConfiguration?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22267191/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com