同一个类中的@WebService和@Path for Soap and Rest

时间:2015-10-15 14:49:32

标签: java web-services rest soap cxf

代码段:

@Path("ExtendedLookupService")
@WebService(
        serviceName = "HubReadServices",
        portName = "HubReadServices",
        targetNamespace = "http://hubread.ml.com/",        
        endpointInterface = "com.ml.hubread.HubReadServices")
public class HubReadServicesImpl implements com.ml.hubread.HubReadServices{ 

@Path和@WebService可以存在于同一个类中吗?

我正在为REST和SOAP实现调用相同的类。

Soap部分工作正常 - 我正在使用CXF。

但是使用Jersey的REST部分失败了以下例外:

[10/15/15 10:30:40:977 EDT] 00000034 PackagesResou I   Scanning for root resource and provider classes in the packages:
  com.ml.das.processors.V1
[10/15/15 10:30:40:985 EDT] 00000034 WebApplicatio I   Initiating Jersey application, version 'Jersey: 1.8 06/24/2011 12:17 PM'
[10/15/15 10:30:41:132 EDT] 00000034 RootResourceU E   The ResourceConfig instance does not contain any root resource classes.
[10/15/15 10:30:41:133 EDT] 00000034 servlet       E com.ibm.ws.webcontainer.servlet.ServletWrapper init SRVE0100E: Uncaught init() exception created by servlet RestServlet in application CEDPHubReadServicesEAR: com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.
        at com.sun.jersey.server.impl.application.RootResourceUriRules.<init>(RootResourceUriRules.java:99)
        at com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1298)
        at com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:169)
        at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:775)
        at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:771)
        at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)

以下是我的web.xml:

<?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>CEDPHubReadServices</display-name>


    <servlet>
        <description>
        </description>
        <display-name>CXFServlet</display-name>
        <servlet-name>CXFServlet</servlet-name>
        <servlet-class>
        org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
    </servlet>



    <servlet-mapping>

        <servlet-name>CXFServlet</servlet-name>
        <url-pattern>/services/*</url-pattern>

    </servlet-mapping>


    <servlet>

        <description>RestServlet for HUB</description>

        <display-name>RestServlet</display-name>

        <servlet-name>RestServlet</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>com.ml.das.processors.V1</param-value>
        </init-param>
            <init-param>
                <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
                <param-value>true</param-value>
            </init-param>       
        <load-on-startup>1</load-on-startup>

    </servlet>


    <servlet-mapping>
        <servlet-name>RestServlet</servlet-name>
        <url-pattern>/restendpoints/*</url-pattern>
    </servlet-mapping>


    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>


</web-app>

根据评论更改后:

<servlet>

    <description>RestServlet for HUB</description>

    <display-name>RestServlet</display-name>

    <servlet-name>RestServlet</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param>
    <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>com.ml.das.processors.V1</param-value>
    </init-param>
        <init-param>
            <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
            <param-value>true</param-value>
        </init-param>       
    <load-on-startup>1</load-on-startup>

</servlet>


<servlet-mapping>
    <servlet-name>RestServlet</servlet-name>
    <url-pattern>/restendpoints/*</url-pattern>
</servlet-mapping>

类别:

package com.ml.das.processors.V1;

@Path("/ExtendedLookupService")
public class HubReadServicesRestImpl{       

0 个答案:

没有答案