【问题标题】:The requested resource is not available while publishing on tomcat在 tomcat 上发布时请求的资源不可用
【发布时间】:2013-05-06 14:52:02
【问题描述】:

我正在尝试使用 tomcat 发布一个简单的 java web 服务。参考下面的截图,我有 HelloWorld.java 这是服务接口和它的 HelloWorldImpl.java 实现类。

我还创建了 web.xmlsun-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


【解决方案1】:

正确的 url 是 http://localhost:8081/MySqlConnect/hello,因为 MySqlConnect 是您的上下文名称,hello 是 Web 服务 url。

它也是一个网络服务,所以要正确访问它,您可以进行 SOAP 调用。

但根本原因是您的 Web 应用程序由于找不到类 javax.xml.ws.soap.AddressingFeature$Responses 而无法启动。

您是否添加了正确的依赖项?如果此类存在,则在这些依赖项中搜索。 ResponseAddressingFeature内部 类。

【讨论】:

  • 我已经尝试过http://localhost:8081/MySqlConnect/hello。但无济于事。
  • 您忘记阅读我回答的第二部分。您的 webapp 尚未启动,因此 url 将不起作用。首先你必须修复错误。
  • 要求 jars 应该被复制到 (1)only tomcat lib 目录或 (2)only web-inf 目录或 (3)both?
  • 你应该把它们放在WEB-INF/lib下
  • 如果我这样做,我会得到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 :(
猜你喜欢
  • 1970-01-01
  • 2017-01-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-18
  • 2010-12-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多