gpt4 book ai didi

spring - WebMvcConfigurationSupport 和 WebMvcConfigurerAdapter 的区别

转载 作者:IT老高 更新时间:2023-10-28 13:45:43 30 4
gpt4 key购买 nike

我想添加资源处理程序。在论坛中,他们使用 WebMvcConfigurationSupport:http://forum.springsource.org/showthread.php?116068-How-to-configure-lt-mvc-resources-gt-mapping-to-take-precedence-over-RequestMapping&p=384066#post384066

文档说 WebMvcConfigurerAdapter:http://static.springsource.org/spring/docs/3.2.x/javadoc-api/org/springframework/web/servlet/config/annotation/EnableWebMvc.html

有什么区别和使用哪一个?两者都有我需要的 addResourceHandlers 方法。

这是我目前的类(class):

@Configuration
@EnableWebMvc
public class WebMvcConfig extends WebMvcConfigurerAdapter {
public @Override void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources");
}

public @Bean TilesViewResolver tilesViewResolver() {
return new TilesViewResolver();
}

public @Bean TilesConfigurer tilesConfigurer() {
TilesConfigurer ret = new TilesConfigurer();
ret.setDefinitions(new String[] { "classpath:tiles.xml" });
return ret;
}
}

最佳答案

答案在您上面引用的文档中:

If the customization options of WebMvcConfigurer do not expose something you need to configure, consider removing the @EnableWebMvc annotation and extending directly from WebMvcConfigurationSupport overriding selected @Bean methods

简而言之,如果@EnableWebMvc 适合您,则无需进一步查看。

关于spring - WebMvcConfigurationSupport 和 WebMvcConfigurerAdapter 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17898606/

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