【发布时间】:2014-06-03 04:40:48
【问题描述】:
我收到“请求的资源不可用”。在 Tomcat 7 中部署我的战争时的消息。
这里是详细信息。
1] WAR 名称 = devMonitor-1.war
2] 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_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>main</display-name>
<servlet>
<servlet-name>Jersey REST Service</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>main.java</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
3] 我的 Jersey RS 课程
*package main.java;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
//Sets the path to base URL + /hello
**@Path("/hello")**
public class Hello {
// This method is called if TEXT_PLAIN is request
@GET
@Produces(MediaType.TEXT_PLAIN)
public String sayPlainTextHello() {
return "Hello Jersey";
}
// This method is called if XML is request
@GET
@Produces(MediaType.TEXT_XML)
public String sayXMLHello() {
return "<?xml version=\"1.0\"?>" + "<hello> Hello Jersey" + "</hello>";
}
// This method is called if HTML is request
@GET
@Produces(MediaType.TEXT_HTML)
public String sayHtmlHello() {
return "<html> " + "<title>" + "Hello Jersey" + "</title>" + "<body><h1>" + "Hello Jersey" + "</body></h1>" + "</html> ";
}
}*
4] 我尝试访问的 URL = localhost:8080/main/rest/hello
5] POM文件,如果有如下任何情况
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.travelport.soa.svcs.pos.uapi.devMonitor</groupId>
<artifactId>devMonitor</artifactId>
<version>1</version>
<packaging>war</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.7</version>
</dependency>
</dependencies>
</project>
6] 我的 tomcat 监视器显示应用程序运行如下,但仍然无法运行。
Path Version Display Name Running Sessions
/devMonitor-1 None specified main true 0
【问题讨论】:
-
true 0 表示应用程序不可访问。当您的应用程序成功运行时,它将为真 1 ,因此请尝试重新部署该应用程序。
-
URI 是 localhost:8080/devMonitor-1/rest/hello
-
我重新部署了,但会话仍然显示为 0。我该怎么办?
-
@MauricePerry localhost:8080/devMonitor-1/rest/hello 也不起作用。 web.xml 中的显示名称也不应该在 URL 中起作用吗?例如localhost:8080/devMonitor-1/main/rest/hello
-
没有。此外,您的 tomcat 监视器清楚地显示它在 /devMonitor-1