【发布时间】:2015-12-11 04:41:12
【问题描述】:
我有一个运行多个 WAR 文件的 tomcat 实例。 tomcat 实例在 Apache 服务器后面被代理,因此上下文路径被剥离。相反,我使用的是子域:
基本上,我的设置如下所示:
http://localhost:8080/app1 -> http://app1.example.com/
http://localhost:8080/app2 -> http://app2.example.com/
我需要做的是使所有重定向上下文相对,因为我不再在 URL 中包含上下文路径。我注意到 Spring Security 允许使用默认类 DefaultRedirectStrategy 将重定向设置为“上下文相关”。为了使重定向正常工作,我必须覆盖多个对象,这样我就可以简单地将具有 contextRelative=false 的 DefaultRedirectStrategy 的默认实例换成我自己创建的具有 contextRelative=true 的 DefaultRedirectStrategy 实例。
有没有更简单的方法可以告诉 spring 我想在没有上下文路径的情况下全局重定向所有 URL?我已经尝试在我的配置中注册 DefaultRedirectStrategy 但没有成功。
@Bean
public RedirectStrategy createRedirectStrategy()
{
// create the redirect strategy to set the urls to context relative
DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
redirectStrategy.setContextRelative(true);
return redirectStrategy;
}
^ 这太容易了。不知道为什么 spring 不允许这个工作。
我是不是找错地方了?
【问题讨论】:
标签: java spring apache tomcat spring-security