两个简单的POST和GET URL,localhost:8080/mdht,在从IntelliJ IDEA运行时都工作得很好。另外,mdht-restlet.war被放到/opt/ Tomcat /webapp部署中,在中显示为运行,在catalina.out中没有错误或警告。获取和发布两个产品404。无论是从命令行mvn package生成WAR文件,还是从IDEA Build-> Build Artifacts...生成WAR文件,结果都是一样的。
如前所述,它在IDEA Run/Debug中运行得非常好。我不知道该看什么。以下是一些相关细节:
web.xml内容:
<servlet>
<servlet-name>mdht-restlet</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.windofkeltia.servlet</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>mdht-restlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>pom.xml为WAR构建插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven-war-plugin.version}</version>
<configuration>
<webResources>
<resource>
<!-- this is relative to the project parent directory -->
<directory>web</directory>
</resource>
</webResources>
</configuration>
</plugin>MdhtRestlet.java
package com.windofkeltia.servlet;
...
@Path( "/mdht-restlet" )
public class MdhtRestlet
{
@POST
@Consumes( MediaType.TEXT_PLAIN )
@Produces( MediaType.TEXT_XML )
public Response postPatientData( @Context HttpServletRequest request, @Context HttpHeaders header )
{
...
}
@GET
@Produces( MediaType.TEXT_PLAIN )
public String getStatusInPlainText()
{
return "The MDHT restlet is up.";
}
}发布于 2018-06-15 20:08:25
答案是Tomcat将WAR文件的名称(在本例中为mdht-restlet.war )视为根(除非将WAR文件重命名为ROOT.war,Tomcat部署到根),所以URL将以http://localhost:8080/mdht-restlet开头。此外,servlet代码在类级别使用@PATH注释来添加到URL中。这就将它扩展到了http://localhost:8080/mdht-restlet/mdht-restlet,因此短URL不会做任何其他操作,除非404。
为什么这是IntelliJ的想法呢?可能是因为Run/Debug Configuration是如何在Server选项卡(对于Tomcat)和Deployment选项卡中的设置之间设置的。这些都没有遵循(在我的第一段中提出的观点),因此给人一种对成功的错误印象(因为他们被劫持了)。
https://stackoverflow.com/questions/50879989
复制相似问题