为 spring-boot WAR 指定上下文路径 [英] Specify context-path for spring-boot WAR

查看:67
本文介绍了为 spring-boot WAR 指定上下文路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个部署为 WAR 的 Spring Boot Web 应用程序.现在,当我将它部署到我的 Tomcat 7 服务器时,它使用 war 文件的名称作为上下文,例如/myartifactid-1.5.4.SNAPSHOT/.我想指定上下文路径,但是

I have a spring boot web application that deploys as a WAR. Right now when I deploy it to my Tomcat 7 server, it uses the name of the war file as the context, such as /myartifactid-1.5.4.SNAPSHOT/. I want to specify the context-path, but

server.contextPath=/mywebapp

似乎只适用于嵌入式 tomcat.我只添加了一个 META-INF/context.xml

seems to only work for embedded tomcat. I've added a META-INF/context.xml with only this

<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="false" path="/mywebapp" />

但这没有任何影响.

这不是 spring-boot 问题,而是与 NetBeans 的行为方式与 Eclipse 不同有关.NetBeans 显然可以识别 context.xml 中的上下文路径参数,但 Eclipse 不能.在 Eclipse 中,您必须修改 Web 项目设置以设置上下文路径.在Eclipse中更改Web项目的Tomcat上下文路径

This is NOT a spring-boot issue, but instead related to how NetBeans behaves differently from Eclipse. NetBeans apparently recognizes the context path parameter in context.xml, but Eclipse doesn't. In Eclipse you have to modify the Web Projects Settings to set the context path. Changing Tomcat context path of web project in Eclipse

推荐答案

由于您将 Spring Boot 应用程序打包为 war(而不是带有嵌入式 tomcat 容器的 jar),因此上下文路径将是 war 的名称.

Since you are packaging your Spring Boot application as a war (as opposed to a jar with an embedded tomcat container) the context path will be the name of the war.

例如,如果您将打包的应用程序命名为 mywebapp.war 并将其放在 Tomcat 的 webapps 下,它将在 /mywebapp

For example if you name your packaged application mywebapp.war and you place it under Tomcat's webapps, it will be available under /mywebapp

这篇关于为 spring-boot WAR 指定上下文路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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