【发布时间】:2013-05-06 14:52:02
【问题描述】:
我正在尝试使用 tomcat 发布一个简单的 java web 服务。参考下面的截图,我有 HelloWorld.java 这是服务接口和它的 HelloWorldImpl.java 实现类。
我还创建了 web.xml 和 sun-jaxws.xml。
当我右键单击项目时,选择 Run As,然后选择 Run on Server,我收到 404 错误消息,如屏幕截图底部所示。
内部浏览器尝试访问的 URL 是 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>
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="HelloWorld" implementation="com.mycompany.service.HelloWorldImpl"
url-pattern="/hello" />
</endpoints>
编辑 1
日志猫
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
编辑 2
按照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
【问题讨论】:
-
你确定它已经部署了吗?可以添加服务器日志吗?
-
请检查已编辑的问题。
-
我也有同样的问题。你找到解决方案了吗?标记的答案对您的情况有效吗?我还阅读了 cmets 并将 jars 放在项目的库下,但仍然收到“java.lang.NoSuchMethodError: com.sun.xml.ws.assembler.TubelineAssemblyController: method
()V not found”错误..
标签: java web-services tomcat7