【发布时间】:2019-08-11 15:53:17
【问题描述】:
我想在我从 maven 加载的 tomcat 嵌入式服务器上部署一个 Web 应用程序: 我的休息端点:
@Path("/test")
public class RestTestController {
@GET
public String doNothing(){
return "A";
}
}
和 Maven 设置:
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<port>8080</port>
<path>/</path>
</configuration>
</plugin>
</plugins>
</build>
在执行mvn clean install 和后来的mvn tomcat7:run 之后,我收到了war tomcat 已启动的消息,但是当我输入 localhost:8080/test 时,我不断收到 404 Not Fount Http 响应。我可能做错了什么?
我应该在 web.xml 中添加某种映射吗?
登录 tomcat 显示我确实部署了我的应用程序:
[INFO] ---------------------< pl.wachkar:take-restaurant >---------------------
[INFO] Building take-restaurant 1.0-SNAPSHOT
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] >>> tomcat7-maven-plugin:2.2:run (default-cli) > process-classes @ take-restaurant >>>
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ take-restaurant ---
(...)
[INFO] --- tomcat7-maven-plugin:2.2:run (default-cli) @ take-restaurant ---
[INFO] Running war on http://localhost:8080/
@编辑 空 web.xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
</web-app>
【问题讨论】:
-
Tomcat 不支持开箱即用的 JAX-RS。您需要将 JAX-RS 实现集成到您的应用程序中。我不相信这时候可以用一个空的 web.xml 文件来完成。
标签: tomcat jakarta-ee web-applications