【问题标题】:Tomcat 8.0.30 Update change redirect behaviourTomcat 8.0.30 更新更改重定向行为
【发布时间】: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


    【解决方案1】:

    这个错误似乎是相关的,并提供了一个可能的解决方法:

    https://bz.apache.org/bugzilla/show_bug.cgi?id=58660

    【讨论】:

    • 我在 8.0.30 上测试过。我将 mapperContextRootRedirectEnabled="true" 添加到 context.xml。它仍然没有重定向:(。我想要重定向回来。
    • 那面旗帜帮助了我。虽然这种变化本身很奇怪——它影响了很多人,但开发人员仍然不确定它是否符合预期。
    猜你喜欢
    • 2014-02-05
    • 2016-07-05
    • 2016-08-18
    • 1970-01-01
    • 2014-12-12
    • 2016-11-16
    • 1970-01-01
    • 1970-01-01
    • 2018-07-24
    相关资源
    最近更新 更多