apache-tomcat-9.0.0.M10:更改META-INF/context.xml中的上下文路径不起作用 [英] apache-tomcat-9.0.0.M10: Change Context-Path in META-INF/context.xml not working

查看:35
本文介绍了apache-tomcat-9.0.0.M10:更改META-INF/context.xml中的上下文路径不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个标准的Tomcat9安装.我只是将helloworld.war放到webapps文件夹中,在META-INF内,将context.xml放到另一个路径中,例如:<上下文路径="/newcontext"/>

但是上下文仍然是 http://localhost/helloworld 而不是 https://tomcat.apache.org/tomcat-9.0-doc/config/context.html ),但这是我在所构建的每个应用程序中都不断观察到的行为.

根据Tomcat文档:

在单个文件(扩展名为".xml")中,$ CATALINA_BASE/conf/[引擎名称]/[主机名称]/目录.上下文路径和版本将从文件的基本名称得出(文件名减去.xml扩展名).该文件将始终优先于Web应用程序包装的任何context.xml文件META-INF目录.

尽管本文讨论了放置在WAR外部的conf文件,但似乎同样适用于 META-INF/context.xml

这是文档为您带来痛苦的建议:

如果要使用上下文路径部署WAR文件或目录与基本文件名无关的话,请执行以下操作之一必须使用选项来防止重复部署:

  1. 禁用autoDeploy和deployOnStartup并在server.xml中定义所有上下文
  2. 将WAR和/或目录放在主机的appBase之外,并使用带有docBase属性的context.xml文件进行定义.

但是,然后他们继续劝阻选项1.

我个人发现,最简单的解决方案是简单地为非根上下文适当地命名WAR文件,而对于根上下文(/)仅使用 ROOT.war 根据Tomcat的约定.

I have a standard Tomcat9 installation. I just put a helloworld.war in the webapps folder and inside the META-INF I put the context.xml with a different path like: <Context path="/newcontext" />

But the context is still http://localhost/helloworld instead http://localhost/newcontext.

I tried so many things, but it is not possible to get Tomcat convinced to use the new path. Anybody who can help? Thanks.

解决方案

I found that Tomcat will simply ignore the path attribute defined in context.xml. This is not explicitly stated in their documentation (https://tomcat.apache.org/tomcat-9.0-doc/config/context.html) but it is a behaviour I keep observing in every application we build.

As per Tomcat docs:

In individual files (with a ".xml" extension) in the $CATALINA_BASE/conf/[enginename]/[hostname]/ directory. The context path and version will be derived from the base name of the file (the file name less the .xml extension). This file will always take precedence over any context.xml file packaged in the web application's META-INF directory.

Though this discusses the conf files placed outside your WAR, it appears that the same applies to META-INF/context.xml

This is what the documentation suggests for your pains:

If you want to deploy a WAR file or a directory using a context path that is not related to the base file name then one of the following options must be used to prevent double-deployment:

  1. Disable autoDeploy and deployOnStartup and define all Contexts in server.xml
  2. Locate the WAR and/or directory outside of the Host's appBase and use a context.xml file with a docBase attribute to define it.

yet, then they go on to discourage Option 1.

I personally found the easiest solution to be simply to name your WAR file appropriately for non-root contexts and for root contexts (/) to simply use ROOT.war as per Tomcat's conventions.

这篇关于apache-tomcat-9.0.0.M10:更改META-INF/context.xml中的上下文路径不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆