【发布时间】:2017-12-25 18:23:50
【问题描述】:
我有一个可以正常工作的 Spring Boot 应用程序。 我按照spring guide 提供的说明创建了一个战争文件 (MyApp.war)。
我已经在 Ubuntu 桌面上安装了 Tomcat 8.5.24 并且运行成功。
如果我从 /opt/tomcat/webapps/ 中删除开箱即用的 ROOT 应用程序,然后将 MyApp.war 复制为 /opt/tomcat/ webapps/ROOT.war 然后我的spring boot应用程序正常工作,并且tomcat服务器成功将静态文件返回给浏览器。没有问题。
我的目标是 tomcat 的开箱即用 ROOT 应用程序必须继续按原样工作,并且静态文件以 MyApp.war 中 index.html 中指定的字符串 /assets 开头strong> 必须成功处理。
所以,我在我的 ubuntu 桌面上成功卸载并重新安装了 tomcat,以验证开箱即用的 tomcat 的 ROOT 应用程序是否正常工作。
在阅读了tomcat documentation以及与context.xml相关的堆栈溢出最爱Q&A's之后,我尝试了以下:
我修改了context.xml,如下图:
$ diff /opt/tomcat/conf/context.xml /opt/tomcat/conf/context.xmlOriginal
19c19
< <Context docBase="MyApp" path="/assets" reloadable="true">
---
> <Context>
上述更改 context.xml 的意图,是当浏览器使用 URL 请求静态文件时 像bootstrap 然后我希望tomcat 从URL new bootstrap 获取文件,即需要进行重定向。
进行上述更改后,我重新启动了 tomcat 并将 MyApp.war 复制到 webapps 目录。当我从 Chrome 开发者工具网络选项卡转到 URL MyAppUrl 时,我可以看到 index.html 已正确加载,如下所示:
Request URL:http://localhost:8080/MyApp/
Request Method:GET
Status Code:200
Remote Address:[::1]:8080
Referrer Policy:no-referrer-when-downgrade
在响应选项卡中,我看到了 index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>MyApp</title>
<link rel="stylesheet" type="text/css" href="/assets/css/bootstrap.css">
...
但是,bootstrap.css 没有正确加载。这是错误,来自网络选项卡,清楚地表明浏览器要求 bootstrap.css 并得到 404 响应。
Request URL:http://localhost:8080/assets/css/bootstrap.css
Request Method:GET
Status Code:404
Remote Address:[::1]:8080
Referrer Policy:no-referrer-when-downgrade
如果我转到 URL success bootstrap URL,我可以验证 bootstrap.css 可以成功检索。
我的问题是:/opt/tomcat/conf/context.xml 中需要进行哪些更改才能使 tomcat 8 从 URL redirectedURL 返回 bootstrap.css每当浏览器请求带有 request URL 的静态资源时?非常感谢,
【问题讨论】:
-
尝试使用
http://localhost:8080/MyApp/assets/css/bootstrap.css。 -
Ataur, '我可以验证如果我转到 URL localhost:8080/MyApp/assets/css/bootstrap.css 可以成功检索 bootstrap.css。我将此 URL 称为成功引导 URL。谢谢,
-
那你的问题是什么?
标签: spring-boot tomcat8 context.xml