【发布时间】:2016-10-10 20:26:23
【问题描述】:
我正在尝试使用 Eclipse 和 Maven 在 Tomcat 上运行一个简单的 Web 服务。
我不断收到此消息:404 请求的资源不可用。
服务器运行良好,没有错误消息。在主机管理器中,网站显示为正在运行。点击它会给...一个404。
控制器是:
package nl.deholtmans.webservice;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
@WebService
@SOAPBinding(style = SOAPBinding.Style.RPC)
public class HelloWebService {
@WebMethod(operationName = "sayHello")
public String sayHello(@WebParam(name="guestname") String guestname){
if(guestname==null){
return "Hello";
}
return "Hello "+ guestname;
}
}
WEB-INF/sun-jaxws.xml:
<?xml version="1.0" encoding="UTF-8"?>
<endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" version="2.0">
<endpoint name="HelloWebService" implementation="nl.deholtmans.webservice.HelloWebService" url-pattern="/helloWebService" ></endpoint>
</endpoints>
WEB-INF/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>jaxwsExample</display-name>
<listener>
<listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
</listener>
<servlet>
<servlet-name>helloWebService</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>helloWebService</servlet-name>
<url-pattern>/helloWebService</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>120</session-timeout>
</session-config>
</web-app>
POM.xml 是:
<?xml version="1.0" encoding="UTF-8"?>
<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>HelloWebService</groupId>
<artifactId>HelloWebService</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>JAX-WS webservice with maven</name>
<dependencies>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.1.3</version>
</dependency>
</dependencies>
<build>
<finalName>HelloService</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
在 Eclipse 中我通常会这样做(例如,对于 Spring MVC):
[1] 项目 > 清洁 [2] 运行方式 > Maven clean [3] 运行方式 > Maven 安装 [4] 运行方式 > 在服务器上运行
我应该使用以下 URL 对其进行测试: http://localhost:8080/HelloWebService/helloWebService
没有错误。没有堆栈跟踪。只有 404,没有可用的资源。通过 Tomcat 管理器,我看到该服务正在运行。
【问题讨论】:
-
能否提供堆栈跟踪和代码库的目录结构?
-
没有堆栈跟踪。一切都已成功部署。此外, localhost:8080 显示主页。 “网站”HelloWebService 指示正在运行。