Spring-Boot war 外部 Tomcat 上下文路径 [英] Spring-Boot war external Tomcat context path

查看:49
本文介绍了Spring-Boot war 外部 Tomcat 上下文路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用 Spring Boot 并且我创建了一个 WAR 而不是 JAR,以部署在常规的 Tomcat 服务器上.一切似乎都很好,只是上下文路径似乎没有正确设置.我的 index.html 中的任何相对路径都不起作用.

We're using Spring Boot and I've created a WAR, instead of a JAR, to deploy on a regular Tomcat server. All seems to work fine, except it appears that the context path isn't being set properly. Any relative paths in my index.html are not working.

在浏览器中加载应用程序时,此链接,

When loading the app in a browser, this link,

<link type="text/css" rel="stylesheet" href="app.min.css" />

试图从 http://localhost:port/app.min.css 而不是 http://localhost:port/contextpath/app.min.css". 尝试在 application.properties 中设置此值不起作用,因为此值似乎仅适用于嵌入式 Tomcat 服务器.

is attempted to be loaded from http://localhost:port/app.min.css instead of http://localhost:port/contextpath/app.min.css". Trying to set this in application.properties does not work as it looks like this value only works for the embedded Tomcat server.

推荐答案

正如您已经猜到的 server.context-path 属性以及所有其他 server.* 属性仅适用于嵌入式 tomcat.如果您使用 WAR 打包部署到外部 tomcat,则必须在外部 tomcat 本身中配置这些值.

As you've already guessed the server.context-path property as well as all the other server.* properties apply to the embedded tomcat only. If you deploy to an external tomcat using WAR packaging you have to configure those values in the external tomcat itself.

我们在这里通常这样做的方法是在 ./conf/Catalina/localhost/ 中有一个上下文描述符,其名称等于您预期的上下文路径,即 contextpath.xml 根据 docs.

The way we usually do this here is to have a context descriptor in ./conf/Catalina/localhost/ with a name that equals your expected context path, i.e. contextpath.xml according to the docs.

这篇关于Spring-Boot war 外部 Tomcat 上下文路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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