我想在tomcat embbeded服务器上部署一个web应用程序,我从maven:我的rest端点加载:
@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时,我不断收到404not Fount响应。我可能做错了什么?我应该在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>
发布于 2019-03-21 04:19:12
你的web.xml是什么样子的?您至少需要一个欢迎文件列表,以便tomcat知道在启动时为哪个文件提供服务
例如:
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
发布于 2019-03-23 03:14:19
我认为您使用web.xml在浏览器.without(可能不完整)中输入了错误的url,您应该创建一个扩展Application
类的类,并使用@ApplicationPath("anyString")
对其进行注释,例如:
import javax.ws.rs.core.Application;
@ApplicationPath("myWebservice")
public class MyConfig extends Application{
}
你不需要实现任何它工作的方法,fine.this类可以在任何包中。用来测试正确的url是:
localhost:port/contextpath/string1/string2
string1是您在应用程序注释(这里是myWebservice)中指定的内容。string2是您在资源类(在您的用例测试中)的路径注释中指定的内容,因此我们有
localhost:8080/contextpath/myWebservice/test
https://stackoverflow.com/questions/55269488
复制相似问题