【发布时间】:2015-12-18 06:09:47
【问题描述】:
我将 Tomcat 8 从 8.0.26 更新到 8.0.30。
在我们的项目中,我们使用 org.springframework:spring-webmvc:4.2.3.RELEASE。
当我们打开上下文根目录时,Tomcat 会在 8.0.26 版本中发送自动重定向 302:http://localhost:8080/vrk > http://localhost:8080/vrk/
从 8.0.30 版开始,不再发送重定向,这会导致相对 URL 出现一些问题。
Java 配置没有改变(我们在那个项目中没有使用 XML)。
public final class WebAppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(final ServletContext servletContext) {
try (
final AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext()) {
rootContext.register(AppConfig.class);
servletContext.addListener(new ContextLoaderListener(rootContext));
}
try (
final AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext()) {
dispatcherContext.register(WebConfig.class);
// dispatcherContext.setServletContext(servletContext); I don't know the reason for this line
final Dynamic dynamic = servletContext.addServlet("dispatcher",
new DispatcherServlet(dispatcherContext));
dynamic.setLoadOnStartup(1);
dynamic.addMapping("/");
dynamic.setMultipartConfig(
new MultipartConfigElement("/tmp", 1024 * 1024 * 5, 1024 * 1024 * 6, 1024 * 1024));
}
}
}
我们如何恢复重定向行为?
这是 Tomcat 8.0.30 中的错误吗?
【问题讨论】:
标签: spring-mvc tomcat8