我正在尝试使用tomcat发布一个简单的java Web服务。参考下面的截图,我有 HelloWorld.java ,它是服务接口及其 HelloWorldImpl.java 实现类。
我也创建了 web.xml 和 sun-jaxws.xml 。
当我右键单击项目时,选择运行方式然后在服务器上运行,我会收到404错误消息,如屏幕截图底部所示。
内部浏览器尝试访问的网址是http://localhost:8081/MySqlConnect/
,其中MySqlConnect
是项目名称。请注意,我使用8081
作为端口号。
我也试过http://localhost:8081/HelloWorld/hello
,但它没有用。
我还提供了以下所有文件的代码。
我无法理解我哪里出错了?任何帮助表示赞赏。
HelloWorldImpl.java
package com.mycompany.service;
import javax.jws.WebService;
@WebService(endpointInterface = "com.mycompany.service.HelloWorld", serviceName = "HelloWorld")
public class HelloWorldImpl implements HelloWorld {
@Override
public String sayGreeting(String name) {
return "Greeting " + name + "!";
}
}
的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems,
Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
<web-app>
<listener>
<listener-class>
com.sun.xml.ws.transport.http.servlet.WSServletContextListener
</listener-class>
</listener>
<servlet>
<servlet-name>hello</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>hello</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>120</session-timeout>
</session-config>
</web-app>
太阳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="HelloWorld" implementation="com.mycompany.service.HelloWorldImpl"
url-pattern="/hello" />
</endpoints>
登入猫
INFO: Starting Servlet Engine: Apache Tomcat/7.0.33
com.sun.xml.ws.transport.http.servlet.WSServletContextListener parseAdaptersAndCreateDelegate
SEVERE: WSSERVLET11: failed to parse runtime descriptor: java.lang.NoClassDefFoundError: javax/xml/ws/soap/AddressingFeature$Responses
java.lang.NoClassDefFoundError: javax/xml/ws/soap/AddressingFeature$Responses
Caused by: java.lang.ClassNotFoundException: javax.xml.ws.soap.AddressingFeature$Responses
根据建议here,我下载了所有库并放在tomcat lib文件夹中,但现在我在日志中收到此错误:
com.sun.xml.ws.transport.http.servlet.WSServletContextListener parseAdaptersAndCreateDelegate
SEVERE: WSSERVLET11: failed to parse runtime descriptor: java.lang.NoSuchMethodError: com.sun.xml.ws.assembler.TubelineAssemblyController: method <init>()V not found
java.lang.NoSuchMethodError: com.sun.xml.ws.assembler.TubelineAssemblyController: method <init>()V not found
如果我将所有库添加到项目中然后尝试运行它,我会收到以下错误:
com.sun.xml.ws.transport.http.servlet.WSServletContextListener parseAdaptersAndCreateDelegate
SEVERE: WSSERVLET11: failed to parse runtime descriptor: com.sun.xml.ws.util.ServiceConfigurationError: com.sun.xml.ws.policy.jaxws.spi.PolicyFeatureConfigurator: Provider com.sun.xml.ws.transport.tcp.policy.TCPTransportFeatureConfigurator is specified in jar:file:/C:/Apache-Tomcat-7/lib/webservices-rt-2.1-b16.jar!/META-INF/services/com.sun.xml.ws.policy.jaxws.spi.PolicyFeatureConfiguratorbut could not be instantiated: java.lang.ClassCastException
com.sun.xml.ws.util.ServiceConfigurationError: com.sun.xml.ws.policy.jaxws.spi.PolicyFeatureConfigurator: Provider com.sun.xml.ws.transport.tcp.policy.TCPTransportFeatureConfigurator is specified in jar:file:/C:/Apache-Tomcat-7/lib/webservices-rt-2.1-b16.jar!/META-INF/services/com.sun.xml.ws.policy.jaxws.spi.PolicyFeatureConfiguratorbut could not be instantiated: java.lang.ClassCastException
请注意: com.sun.xml.ws.policy.jaxws.spi.PolicyFeatureConfigurator但无法实例化:java.lang.ClassCastException
答案 0 :(得分:2)
正确的网址是 http://localhost:8081/MySqlConnect/hello
,因为 MySqlConnect 是您的上下文的名称, hello 是网络服务网址。
此外,它还是一个Web服务,以便正确访问它,您可以进行SOAP调用。
但根本原因是由于无法找到课程javax.xml.ws.soap.AddressingFeature$Responses
,您的网络应用程序无法启动。
您是否添加了正确的依赖项?如果此类存在,则在这些依赖项中搜索。 Response
是AddressingFeature
的内部类。