Spring 使用 Apache CXF 的 Web 服务未部署到客户端服务器 (weblogic)

Spring Webservices using Apache CXF is not getting deployed in the client server (weblogic)

我正在为应用程序构建 spring 网络服务。我使用 apache cxf 创建 web 服务,使用 maven 构建 war。我正在使用 weblogic 12c 在我的 PC 中部署 web 服务。我正在使用 "org.codehaus.jackson.jaxrs.JacksonJsonProvider" 作为 jsonProvider。代码被部署在服务器 运行 机器上,没有任何错误。但是当我尝试在具有 weblogic 12.2.1 的客户端计算机中部署相同的代码时,部署失败并出现以下错误:

"Jersey" failed to preload on startup in Web application: "broker-ws.war".

<[ACTIVE] ExecuteThread: '12' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1490020025257> <BEA-101216> <Servlet: "Jersey" failed to preload on startup in Web application: "broker-ws.war".
    at com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170)
    at com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136)
    at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:199)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:795)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:790)
    at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:491)
    at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:321)
    at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:605)
    at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:207)
    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:376)
    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:559)
    at javax.servlet.GenericServlet.init(GenericServlet.java:240)
    at weblogic.jaxrs.server.portable.servlet.ServletContainer.init(ServletContainer.java:121)
    at weblogic.servlet.internal.StubSecurityHelper$ServletInitAction.run(StubSecurityHelper.java:337)
    at weblogic.servlet.internal.StubSecurityHelper$ServletInitAction.run(StubSecurityHelper.java:288)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
    at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
    at weblogic.servlet.internal.StubSecurityHelper.initServletInstance(StubSecurityHelper.java:98)
    at weblogic.servlet.internal.StubSecurityHelper.createServlet(StubSecurityHelper.java:86)
    at weblogic.servlet.internal.StubLifecycleHelper.createOneInstance(StubLifecycleHelper.java:71)
    at weblogic.servlet.internal.StubLifecycleHelper.<init>(StubLifecycleHelper.java:57)
    at weblogic.servlet.internal.StubLifecycleHelper.<init>(StubLifecycleHelper.java:31)
    at weblogic.servlet.internal.ServletStubImpl.initStubLifecycleHelper(ServletStubImpl.java:656)
    at weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubImpl.java:600)
    at weblogic.servlet.internal.WebAppServletContext.preloadServlet(WebAppServletContext.java:1974)
    at weblogic.servlet.internal.WebAppServletContext.loadServletsOnStartup(WebAppServletContext.java:1951)
    at weblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServletContext.java:1841)
    at weblogic.servlet.internal.WebAppServletContext.start(WebAppServletContext.java:2871)
    at weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:1661)
    at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:823)
    at weblogic.application.internal.ExtensibleModuleWrapper$StartStateChange.next(ExtensibleModuleWrapper.java:360)
    at weblogic.application.internal.ExtensibleModuleWrapper$StartStateChange.next(ExtensibleModuleWrapper.java:356)
    at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:42)
    at weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:138)
    at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:124)

我没有在项目中的任何地方明确引用 Jersey,但我正在使用 jax-rs,它正在寻找 Jersey.The 我机器中的 weblogic 服务器有 Jersey jar,但客户端机器中的 weblogic 没有没有球衣罐。我尝试将以下罐子添加到我的 pom.xml:

<!--  https://mvnrepository.com/artifact/org.glassfish.jersey.bundles/jaxrs-ri -->
     <dependency>
            <groupId>org.glassfish.jersey.bundles</groupId>
            <artifactId>jaxrs-ri</artifactId>
            <version>2.25.1</version>
        </dependency>   
        <dependency>
            <groupId>org.glassfish.hk2</groupId>
            <artifactId>hk2-api</artifactId>
            <version>2.5.0-b32</version>
        </dependency>

        <dependency>
            <groupId>org.glassfish.hk2</groupId>
            <artifactId>hk2-locator</artifactId>
            <version>2.5.0-b32</version>
        </dependency> 

        <dependency>
            <groupId>org.glassfish.hk2</groupId>
            <artifactId>hk2-utils</artifactId>
            <version>2.5.0-b32</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.glassfish.hk2/hk2-inhabitant-generator -->
        <dependency>
            <groupId>org.glassfish.hk2</groupId>
            <artifactId>hk2-inhabitant-generator</artifactId>
            <version>2.5.0-b19</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/javax.inject/javax.inject -->
        <!-- https://mvnrepository.com/artifact/org.apache.servicemix.bundles/org.apache.servicemix.bundles.javax-inject -->
        <dependency>
            <groupId>org.apache.servicemix.bundles</groupId>
            <artifactId>org.apache.servicemix.bundles.javax-inject</artifactId>
            <version>1_2</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.glassfish.jersey.core/jersey-client -->
        <dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-client</artifactId>
            <version>2.25.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.glassfish.jersey.bundles.repackaged/jersey-guava -->
        <dependency>
            <groupId>org.glassfish.jersey.bundles.repackaged</groupId>
            <artifactId>jersey-guava</artifactId>
            <version>2.25</version>
        </dependency>

但是我无法毫无错误地部署应用程序。我现在收到一个不同的错误。

java.lang.IllegalStateException: No generator was provided and there is no default generator registered

请在 spring-config 文件中找到我的 jax-rs 配置。

<jaxrs:server id="restService" address="/rest">
        <jaxrs:serviceBeans>
            <ref bean="userService" />
            <ref bean="billingService" />
        </jaxrs:serviceBeans>
        <jaxrs:providers>
            <ref bean='jsonProvider' />
        </jaxrs:providers>
        <jaxrs:inInterceptors>
            <bean class="com.brokerws.interceptor.WSLoggingRequestInterceptor" />
        </jaxrs:inInterceptors>
        <jaxrs:outInterceptors>
            <bean class="com.brokerws.interceptor.WSLoggingResponseInterceptor" />
        </jaxrs:outInterceptors>
    </jaxrs:server>

请在下面找到我的 web.xml

    <?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    metadata-complete="true" version="3.0">
    <display-name>SuppApp</display-name>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/app-beans.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <servlet>
        <servlet-name>CXFServlet</servlet-name>
        <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>CXFServlet</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>
    <servlet>
        <servlet-name>health-check</servlet-name>
        <servlet-class>com.suddenlink.util.HealthCheckServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>health-check</servlet-name>
        <url-pattern>/healthCheck</url-pattern>
    </servlet-mapping>

    <filter>
        <filter-name>Logback-MDC-Filter</filter-name>
        <filter-class>com.suddenlink.traceability.filter.HttpHeaderServletFilter</filter-class>
        <init-param>
            <param-name>application_name</param-name>
            <param-value>broker-ws</param-value>
        </init-param>
        <init-param>
            <param-name>application_type</param-name>
            <param-value>ws</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>Logback-MDC-Filter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

</web-app>

谁能告诉我我缺少什么here.I尝试了互联网上提供的各种解决方案,但对我没有任何效果。

终于找到了问题的根本原因。这是 spring webapp 版本,它使 weblogic 服务器寻找 jersey 依赖项。我将 webapp 版本从 3.0 更改为 2.5,错误消失了。希望这对 运行 解决这个问题的人有所帮助,因为这花了将近两天的时间才弄清楚实际发生了什么。