我有一个使用胸腺thyeaf作为模板引擎的弹簧启动应用程序,我添加了一个默认控制器,该默认控制器应在部署在服务器上时将其重定向到主页,下面的控制器代码段:
@Controller
public class HomeController
{
@RequestMapping("/")
public String index()
{
return "index";
}
}
通过ViewResolver到匹配的网页来解决该索引。
部署生成的战争' app.war ;在独立的tomcat实例上,该应用程序工作正常,我被重定向到主页( localhost:xxx/context_path/index (,&quort' local -host:xxx/xxx/< context_path_path>"也将重定向到正确的页面。
在WebLogic上部署时,尝试访问URL时会出现错误:&quot' localhost:xxx/context_path '当我手动添加&quot'/"。
我找到了本教程https://o7planning.org/en/11245/deploying-spring-spring-mvc-on-oracle-weblogic-server,建议添加/添加/weblogic.xml文件。
但是,在强迫上下文 - quot到'/&quot&quot&quot&quot&quot&quort the weblogic上的应用程序的主页URL不再是相同的(' localhost:xxx/index '而不是' localhost:xxx/war_name/index quot。
总结一下,Tomcat自动添加" /"。在上下文根上扎根而不配置上下文根。
如何在不必在weblogic.xml上配置上下文 -
来获得相同的行为。我正在使用WebLogic Server 12c。
i任何人仍然存在相同的问题,解决方案是在Spring(默认索引文件(上使用的静态文件进行简单的hack。
<script type="text/javascript">
if (window.location.pathname.slice(-1) !== '/') {
window.location.assign(window.location.pathname + '/');
}
</script>