简体   繁体   English

Undertow和Tomcat的Spring Boot .war上下文路径

[英]Spring Boot .war context path for Undertow and Tomcat

I have a Spring Boot application which I will deploy as a .war file in existing Tomcat and Undertow(Wildfly) containers. 我有一个Spring Boot应用程序,它将作为.war文件部署在现有的Tomcat和Undertow(Wildfly)容器中。 How can I configure the context path from within the application? 如何从应用程序内部配置上下文路径?

I know I can use the .war name directly, but I dont want to do that since the .war name contains version information etc. 我知道我可以直接使用.war名称,但是我不想这样做,因为.war名称包含版本信息等。

From Tomcat configuration docs Defining a context: 来自Tomcat配置文档定义上下文:

Individual Context elements may be explicitly defined: 各个上下文元素可以明确定义:

  • In an individual file at /META-INF/context.xml inside the application files. 在应用程序文件内/META-INF/context.xml中的单个文件中。 Optionally (based on the Host's copyXML attribute) this may be copied to $CATALINA_BASE/conf/[enginename]/[hostname]/ and renamed to (可选)(基于主机的copyXML属性),可以将其复制到$ CATALINA_BASE / conf / [enginename] / [hostname] /并重命名为
    application's base file name plus a ".xml" extension. 应用程序的基本文件名加上“ .xml”扩展名。
  • ... ...

Also note: 另请注意:

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: 如果要使用与基本文件名无关的上下文路径来部署WAR文件或目录,则必须使用以下选项之一来防止双重部署:

  • Disable autoDeploy and deployOnStartup and define all Contexts in server.xml 禁用autoDeploy和deployOnStartup并在server.xml中定义所有上下文
  • 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. 在主机的appBase之外找到WAR和/或目录,并使用带有docBase属性的context.xml文件对其进行定义。

Also this is along the lines of what you are looking for How to set the context path of a web application in Tomcat 7.0 同样,这也是您要寻找的方法如何在Tomcat 7.0中设置Web应用程序的上下文路径

For undertow, if it's used as a web server in the wildfly AS try it with a jboss-web.xml like: https://stackoverflow.com/a/28475123/4807777 对于undertow,如果它在wildfly AS中用作Web服务器,请尝试使用jboss-web.xml,例如: https ://stackoverflow.com/a/28475123/4807777

You can do this in the by adding a /WEB-INF/jboss-web.xml file in the application that you deploy: 您可以通过在部署的应用程序中添加/WEB-INF/jboss-web.xml文件来执行此操作:

<?xml version="1.0" encoding="UTF-8"?> <jboss-web xmlns="http://www.jboss.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd"> <context-root>/</context-root> </jboss-web>

As noted here: https://stackoverflow.com/a/28475123/912829 如此处所述: https : //stackoverflow.com/a/28475123/912829

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM