![使用上下文版本控制在 Tomcat 7 上部署 Java 应用程序](https://linux22.com/image/678502/%E4%BD%BF%E7%94%A8%E4%B8%8A%E4%B8%8B%E6%96%87%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6%E5%9C%A8%20Tomcat%207%20%E4%B8%8A%E9%83%A8%E7%BD%B2%20Java%20%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F.png)
我正在开发一个基于 Spark 迷你框架构建的 API(http://sparkjava.com/)
每当我通过 Maven 构建一个包,然后将其上传到 Tomcat 7 下的 webapps/ 文件夹时。
(真实名称已被替换为 TestProject,以避免泄露任何专有信息)
如果我编译该项目并将其命名为TestProject.war,它将加载以下信息:
小路:/测试项目
版本:未指定
打开后http://localhost:8080/测试项目/然后我得到了预期的输出:
{"code":400,"message":"请求中未指定授权信息"}
如果我将文件重命名为 TestProject##0.0.1-SNAPSHOT_20160308.161909.war 并重新启动 Tomcat,则应用程序将加载以下详细信息:
小路:/测试项目
版本:0.0.1-SNAPSHOT_20160308.161909
不幸的是,当打开相同的 URL 时,Tomcat 返回 404:
HTTP 状态 404 - /
类型状况报告
信息/
描述请求的资源不可用。Apache
雄猫/7.0.67
$ cat web.xml
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>RESTFul Web Service</display-name>
<filter>
<filter-name>SparkFilter</filter-name>
<filter-class>spark.servlet.SparkFilter</filter-class>
<init-param>
<param-name>applicationClass</param-name>
<param-value>TestProjectService</param-value>
</init-param>
</filter>
<filter>
<filter-name>CorsFilter</filter-name>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
<init-param>
<param-name>cors.allowed.origins</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>cors.allowed.methods</param-name>
<param-value>GET,POST,HEAD,OPTIONS,PUT</param-value>
</init-param>
<init-param>
<param-name>cors.allowed.headers</param-name>
<param-value>Content-Type,X-Requested-With,accept,authorization,scope,Origin,Access-Control-Request-Method,Access-Control-Request-Headers</param-value>
</init-param>
<init-param>
<param-name>cors.exposed.headers</param-name>
<param-value>Access-Control-Allow-Origin,Access-Control-Allow-Credentials</param-value>
</init-param>
<init-param>
<param-name>cors.support.credentials</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>cors.preflight.maxage</param-name>
<param-value>10</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>SparkFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
$ cat context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context antiResourceLocking="true" path="/TestProject"/>
我根本不知道是什么导致了这个问题。唯一的区别是 .war 的名称
系统信息:
OS: Windows 10 x64
Java: java version "1.8.0_73"
Java(TM) SE Runtime Environment (build 1.8.0_73-b02)
Java HotSpot(TM) 64-Bit Server VM (build 25.73-b02, mixed mode)
C:\OtherPrograms\apache-tomcat-7.0.67>bin\startup.bat
Using CATALINA_BASE: "C:\OtherPrograms\apache-tomcat-7.0.67"
Using CATALINA_HOME: "C:\OtherPrograms\apache-tomcat-7.0.67"
Using CATALINA_TMPDIR: "C:\OtherPrograms\apache-tomcat-7.0.67\temp"
Using JRE_HOME: "C:\Program Files\Java\jdk1.8.0_73"
Using CLASSPATH: "C:\OtherPrograms\apache-tomcat-7.0.67\bin\bootstrap.jar;C:\OtherPrograms\apache-tomcat-7.0.67\bin\tomcat-juli.jar"