我有一个像这样的 Spring MVC 配置类:
@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter{
@Bean
public InternalResourceViewResolver configureInternalResourceViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/views/");
resolver.setSuffix(".jsp");
return resolver;
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations(
"/resources/");
}
}
我在使用尾部斜杠映射 URL 时遇到问题,类似于this https://stackoverflow.com/questions/11560916/spring-mvc-3-1-how-to-map-urls-with-a-trailing-slash。所以我想添加RequestMappingHandlerMapping
课程,但根据我得到的指示there http://forum.spring.io/forum/spring-projects/web/111171-configuring-requestmappinghandlermapping-when-using-mvc-annotation-driven我需要extend WebMvcConfigurationSupport
类并实现requestMappingHandlerMapping()
方法,但不幸的是我已经扩展了 WebMvcConfigurationSupport 类以进行资源映射。有什么方法可以将请求映射处理程序添加到我的类中吗?
NOTE:我正在使用 Spring 版本 3.1.1.RELEASE
使用 WebMvcConfigurationSupport 覆盖 requestMappingHandlerMapping 可能会关闭 Spring Boot 的默认配置。更好的方法可能是将 WebMvcRegistrations 用作,
@Configuration
static class CustomRequestMappingHandlerMapping {
@Bean
public WebMvcRegistrationsAdapter webMvcRegistrationsHandlerMapping() {
return new WebMvcRegistrationsAdapter() {
@Override
public RequestMappingHandlerMapping getRequestMappingHandlerMapping() {
return new MyRequestMappingHandlerMapping();
}
};
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)