代码之家  ›  专栏  ›  技术社区  ›  Shyam Kumar Sundarakumar

JBOSS和Java 6中注释的WebService中的CLSASTASTExtExchange

  •  1
  • Shyam Kumar Sundarakumar  · 技术社区  · 16 年前

    我使用jboss 4.0使用@web service注释创建简单的Web服务,如中所述。 http://www.jtraining.com/blogs/java-web-services-getting-started.html . 但是,当我像servlet一样访问服务时(根据本文中的说明),我得到的是 ClassCastException 声明我的带批注的WebService类不能强制转换为 javax.servlet.Servlet .

    我哪里出错了?

    The classes are given below:

    //SimpleServiceWS.java    
    import javax.jws.WebService;
    
    @WebService()
    public interface SimpleServiceWS {
        public String simpleMethod();
    }
    

    //SimpleServiceImpl.java
    import javax.jws.WebService;
    
    @WebService( serviceName="SimpleService", portName="SimpleServicePort", endpointInterface="edu.shyam.ws.SimpleServiceWS")
    public class SimpleServiceImpl implements SimpleServiceWS {
    
        public String simpleMethod() {
            return "Simple response";
        }
    }
    

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
        <display-name>Service</display-name>
        <welcome-file-list>
            <welcome-file>/SimpleServiceWS</welcome-file>
        </welcome-file-list>
        <servlet>
            <servlet-name>SimpleServiceWS</servlet-name>
            <servlet-class>edu.shyam.ws.SimpleServiceWS</servlet-class>
        </servlet>
        <servlet-mapping>
            <servlet-name>SimpleServiceWS</servlet-name>
            <url-pattern>/SimpleService</url-pattern>
        </servlet-mapping>
    </web-app>
    

    stacktrace如下:

    java.lang.ClassCastException: SimpleServiceImpl cannot be cast to javax.servlet.Servlet
        at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1048)
        at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:750)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:130)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
        at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
        at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
        at java.lang.Thread.run(Unknown Source)
    
    2 回复  |  直到 14 年前
        1
  •  1
  •   Georgy Bolyuba    16 年前

    看起来,JBoss4.0还不足以运行您试图运行的Web服务。JBoss4.0.5(最新的4.0版本)有一个旧的JBossW实现。您需要较新版本的jbossws,它将与JDK1.5及更高版本上的注释一起工作。

    注意:接口和类都在JBoss5.1.0和4.2.3中工作。对于您来说,获得另一个版本的JBossAS可能更容易。

        2
  •  0
  •   Hrzio    14 年前

    我在jboss上和6.1有同样的问题,我在这个服务器上有一个带有注释的webservices的应用程序,并且部署成功,但是没有在一个新的服务器上;分析这个问题,我意识到我的新war应用程序有一个web-inf/lib/目录,其中有一些jax jar,jboss已经有了,但可能是在一些不同的版本中,所以我删除了web-inf/lib。/重新部署了WebApplication,一切正常。I think this could be a ClassLoader issue or maybe the JAX version I used to develop my WebService in NetBeans was not compatible with JBoss AS 6.1.