Weblogic 12.1.3 - CXF 3.x - REST - 部署错误

Weblogic 12.1.3 - CXF 3.x - REST - Deployment Error

我正在尝试在 Weblogic 12.1.3 上部署一个简单的 'CXF 3.1.2' REST 应用程序并收到此错误。 (但适用于 Tomcat 8)

weblogic.application.ModuleException: com.sun.jersey.api.container.ContainerException: ResourceConfig 实例 不包含任何根资源 类.

我也试过在Weblogic中部署下面的库,还是一样的错误。

C:\Oracle\Middleware2\Oracle_Home\wlserver\common\deployable-libraries\jax-rs-2.0.war

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.0"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

    <display-name>mdm</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring-context.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>

</web-app>

spring-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:cxf="http://cxf.apache.org/core"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
    http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
    http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
    http://www.springframework.org/schema/tx  http://www.springframework.org/schema/tx/spring-tx.xsd">

    <!-- Service -->
    <context:component-scan base-package="com.jai.service" />

    <jaxrs:server id="mdmCxfServer" address="/"  >

        <jaxrs:serviceBeans>
            <ref bean="airlineService" />
        </jaxrs:serviceBeans>

        <jaxrs:extensionMappings>
            <entry key="json" value="application/json" />
        </jaxrs:extensionMappings>

        <jaxrs:providers>
            <bean class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider" />
        </jaxrs:providers>

        <jaxrs:features>
            <cxf:logging />
        </jaxrs:features>
    </jaxrs:server>

完整错误日志

    Aug 20, 2015 5:37:35 PM weblogic.jaxrs.server.portable.servlet.JerseyServletContainerInitializer onStartup
    INFO: Number of JAX-RS specific classes to be examined:22
    Aug 20, 2015 5:36:42 PM org.jasig.cas.services.DefaultServicesManagerImpl reload
    INFO: Reloading registered services.
    Aug 20, 2015 5:37:44 PM org.jasig.cas.services.DefaultServicesManagerImpl load
    INFO: Loaded 4 services.
    Aug 20, 2015 5:37:44 PM org.jasig.cas.services.DefaultServicesManagerImpl load
    INFO: Loaded 4 services.
    Aug 20, 2015 5:37:44 PM weblogic.jaxrs.server.portable.servlet.JerseyServletContainerInitializer onStartup
    INFO: The list of resource packages:org.apache.cxf.jaxrs.validation com.fasterxml.jackson.jaxrs.base org.apache.cxf.jaxr
    s.provider com.fasterxml.jackson.jaxrs.json org.apache.cxf.jaxrs.servlet
    Aug 20, 2015 5:37:44 PM org.springframework.web.context.ContextLoader initWebApplicationContext
    INFO: Root WebApplicationContext: initialization started
    Aug 20, 2015 5:37:44 PM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh
    INFO: Refreshing Root WebApplicationContext: startup date [Thu Aug 20 17:37:44 BST 2015]; root of context hierarchy
    Aug 20, 2015 5:37:44 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
    INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/spring-context.xml]
    Aug 20, 2015 5:37:44 PM org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor <init>
    INFO: JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
    Aug 20, 2015 5:37:44 PM org.springframework.jdbc.datasource.DriverManagerDataSource setDriverClassName
    INFO: Loaded JDBC driver: oracle.jdbc.OracleDriver
    Aug 20, 2015 5:37:44 PM org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean createNativeEntityManagerFact
    ory
    INFO: Building JPA container EntityManagerFactory for persistence unit 'default'
    Aug 20, 2015 5:37:44 PM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation
    INFO: HHH000204: Processing PersistenceUnitInfo [
            name: default
            ...]
    Aug 20, 2015 5:37:44 PM org.hibernate.Version logVersion
    INFO: HHH000412: Hibernate Core {4.3.11.Final}
    Aug 20, 2015 5:37:44 PM org.hibernate.cfg.Environment <clinit>
    INFO: HHH000206: hibernate.properties not found
    Aug 20, 2015 5:37:44 PM org.hibernate.cfg.Environment buildBytecodeProvider
    INFO: HHH000021: Bytecode provider name : javassist
    Aug 20, 2015 5:37:45 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
    INFO: HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
    Aug 20, 2015 5:37:45 PM org.hibernate.dialect.Dialect <init>
    INFO: HHH000400: Using dialect: org.hibernate.dialect.Oracle10gDialect
    Aug 20, 2015 5:37:45 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
    INFO: HHH000397: Using ASTQueryTranslatorFactory
    Aug 20, 2015 5:37:45 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
    INFO: HHH000228: Running hbm2ddl schema update
    Aug 20, 2015 5:37:45 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
    INFO: HHH000102: Fetching database metadata
    Aug 20, 2015 5:37:45 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
    INFO: HHH000396: Updating schema
    Aug 20, 2015 5:37:46 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
    INFO: HHH000261: Table found: AIRLINES
    Aug 20, 2015 5:37:46 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
    INFO: HHH000037: Columns: [country_code, iata, countrycode, name, callsign, alias, icao, id, call_sign]
    Aug 20, 2015 5:37:46 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
    INFO: HHH000108: Foreign keys: []
    Aug 20, 2015 5:37:46 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
    INFO: HHH000126: Indexes: [sys_c0013697]
    Aug 20, 2015 5:37:46 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
    INFO: HHH000232: Schema update complete
    Aug 20, 2015 5:37:46 PM org.apache.cxf.endpoint.ServerImpl initDestination
    INFO: Setting the server's publish address to be /
    Aug 20, 2015 5:37:46 PM org.springframework.web.context.ContextLoader initWebApplicationContext
    INFO: Root WebApplicationContext: initialization completed in 2311 ms
    Aug 20, 2015 5:37:46 PM com.sun.jersey.api.core.PackagesResourceConfig init
    INFO: Scanning for root resource and provider classes in the packages:
      org.apache.cxf.jaxrs.validation
      com.fasterxml.jackson.jaxrs.base
      org.apache.cxf.jaxrs.provider
      com.fasterxml.jackson.jaxrs.json
      org.apache.cxf.jaxrs.servlet
    Aug 20, 2015 5:37:46 PM com.sun.jersey.api.core.ScanningResourceConfig init
    INFO: No root resource classes found.
    Aug 20, 2015 5:37:46 PM com.sun.jersey.api.core.ScanningResourceConfig logClasses
    INFO: Provider classes found:
      class org.apache.cxf.jaxrs.provider.FormEncodingProvider
      class org.apache.cxf.jaxrs.provider.RequestDispatcherProvider
      class org.apache.cxf.jaxrs.validation.ValidationExceptionMapper
      class org.apache.cxf.jaxrs.provider.MultipartProvider
      class org.apache.cxf.jaxrs.provider.JAXBElementProvider
      class org.apache.cxf.jaxrs.provider.SourceProvider
      class com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider
      class org.apache.cxf.jaxrs.validation.JAXRSBeanValidationOutInterceptor
      class com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider
      class org.apache.cxf.jaxrs.provider.XSLTJaxbProvider
      class com.fasterxml.jackson.jaxrs.json.JsonParseExceptionMapper
      class com.fasterxml.jackson.jaxrs.base.JsonMappingExceptionMapper
      class org.apache.cxf.jaxrs.provider.CachingMessageBodyWriter
      class com.fasterxml.jackson.jaxrs.base.JsonParseExceptionMapper
      class org.apache.cxf.jaxrs.provider.XPathProvider
      class org.apache.cxf.jaxrs.provider.DataBindingProvider
      class org.apache.cxf.jaxrs.provider.DataSourceProvider
      class org.apache.cxf.jaxrs.provider.CachingMessageBodyReader
      class com.fasterxml.jackson.jaxrs.json.JsonMappingExceptionMapper
      class org.apache.cxf.jaxrs.provider.AbstractCachingMessageProvider
      class org.apache.cxf.jaxrs.validation.JAXRSBeanValidationInInterceptor
    Aug 20, 2015 5:37:46 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
    INFO: Initiating Jersey application, version 'Jersey: 1.18.1 02/19/2014 03:28 AM'
    Aug 20, 2015 5:37:46 PM com.sun.jersey.server.impl.application.RootResourceUriRules <init>
    SEVERE: The ResourceConfig instance does not contain any root resource classes.
    <Aug 20, 2015 5:37:46 PM BST> <Error> <com.sun.jersey.server.impl.application.RootResourceUriRules> <BEA-000000> <The Re
    sourceConfig instance does not contain any root resource classes.>
    Aug 20, 2015 5:37:46 PM com.sun.jersey.spi.inject.Errors processErrorMessages
    SEVERE: The following errors and warnings have been detected with resource and/or provider classes:
      SEVERE: Missing dependency for method public void org.apache.cxf.jaxrs.provider.RequestDispatcherProvider.setMessageCo
    ntext(org.apache.cxf.jaxrs.ext.MessageContext) at parameter at index 9
      SEVERE: Missing dependency for field: private org.apache.cxf.jaxrs.ext.MessageContext org.apache.cxf.jaxrs.provider.Mu
    ltipartProvider.mc
      SEVERE: Missing dependency for method public void org.apache.cxf.jaxrs.provider.JAXBElementProvider.setMessageContext(
    org.apache.cxf.jaxrs.ext.MessageContext) at parameter at index 1
      SEVERE: Missing dependency for field: private org.apache.cxf.jaxrs.ext.MessageContext org.apache.cxf.jaxrs.provider.So
    urceProvider.context
      SEVERE: Missing dependency for method public void org.apache.cxf.jaxrs.provider.JAXBElementProvider.setMessageContext(
    org.apache.cxf.jaxrs.ext.MessageContext) at parameter at index 15
      SEVERE: Missing dependency for method public void org.apache.cxf.jaxrs.provider.AbstractCachingMessageProvider.setMess
    ageContext(org.apache.cxf.jaxrs.ext.MessageContext) at parameter at index 3
      SEVERE: Missing dependency for field: private org.apache.cxf.jaxrs.ext.MessageContext org.apache.cxf.jaxrs.provider.Fo
    rmEncodingProvider.mc
      SEVERE: Missing dependency for method public void org.apache.cxf.jaxrs.provider.AbstractCachingMessageProvider.setMess
    ageContext(org.apache.cxf.jaxrs.ext.MessageContext) at parameter at index 3
    <Aug 20, 2015 5:37:46 PM BST> <Error> <com.sun.jersey.spi.inject.Errors> <BEA-000000> <The following errors and warnings
     have been detected with resource and/or provider classes:
      SEVERE: Missing dependency for method public void org.apache.cxf.jaxrs.provider.RequestDispatcherProvider.setMessageCo
    ntext(org.apache.cxf.jaxrs.ext.MessageContext) at parameter at index 9
      SEVERE: Missing dependency for field: private org.apache.cxf.jaxrs.ext.MessageContext org.apache.cxf.jaxrs.provider.Mu
    ltipartProvider.mc
      SEVERE: Missing dependency for method public void org.apache.cxf.jaxrs.provider.JAXBElementProvider.setMessageContext(
    org.apache.cxf.jaxrs.ext.MessageContext) at parameter at index 1
      SEVERE: Missing dependency for field: private org.apache.cxf.jaxrs.ext.MessageContext org.apache.cxf.jaxrs.provider.So
    urceProvider.context
      SEVERE: Missing dependency for method public void org.apache.cxf.jaxrs.provider.JAXBElementProvider.setMessageContext(
    org.apache.cxf.jaxrs.ext.MessageContext) at parameter at index 15
      SEVERE: Missing dependency for method public void org.apache.cxf.jaxrs.provider.AbstractCachingMessageProvider.setMess
    ageContext(org.apache.cxf.jaxrs.ext.MessageContext) at parameter at index 3
      SEVERE: Missing dependency for field: private org.apache.cxf.jaxrs.ext.MessageContext org.apache.cxf.jaxrs.provider.Fo
    rmEncodingProvider.mc
      SEVERE: Missing dependency for method public void org.apache.cxf.jaxrs.provider.AbstractCachingMessageProvider.setMess
    ageContext(org.apache.cxf.jaxrs.ext.MessageContext) at parameter at index 3>
    <Aug 20, 2015 5:37:46 PM BST> <Error> <HTTP> <BEA-101216> <Servlet: "Jersey" failed to preload on startup in Web applica
    tion: "mdm.war".
    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:1359)
            at com.sun.jersey.server.impl.application.WebApplicationImpl.access0(WebApplicationImpl.java:180)
            at com.sun.jersey.server.impl.application.WebApplicationImpl.f(WebApplicationImpl.java:799)
            at com.sun.jersey.server.impl.application.WebApplicationImpl.f(WebApplicationImpl.java:795)
            Truncated. see log file for complete stacktrace
    >
    Aug 20, 2015 5:37:46 PM org.springframework.web.context.support.XmlWebApplicationContext doClose
    INFO: Closing Root WebApplicationContext: startup date [Thu Aug 20 17:37:44 BST 2015]; root of context hierarchy
    Aug 20, 2015 5:37:46 PM org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean destroy
    INFO: Closing JPA EntityManagerFactory for persistence unit 'default'
    <Aug 20, 2015 5:37:47 PM BST> <Error> <Deployer> <BEA-149265> <Failure occurred in the execution of deployment request w
    ith ID "51293817685089" for task "14". Error is: "weblogic.application.ModuleException: com.sun.jersey.api.container.Con
    tainerException: The ResourceConfig instance does not contain any root resource classes."
    weblogic.application.ModuleException: com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does
    not contain any root resource classes.
            at weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:140)
            at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:124)
            at weblogic.application.internal.flow.ModuleStateDriver.next(ModuleStateDriver.java:216)
            at weblogic.application.internal.flow.ModuleStateDriver.next(ModuleStateDriver.java:211)
            at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:42)
            Truncated. see log file for complete stacktrace
    Caused By: com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resour
    ce classes.
            at com.sun.jersey.server.impl.application.RootResourceUriRules.<init>(RootResourceUriRules.java:99)
            at com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1359)
            at com.sun.jersey.server.impl.application.WebApplicationImpl.access0(WebApplicationImpl.java:180)
            at com.sun.jersey.server.impl.application.WebApplicationImpl.f(WebApplicationImpl.java:799)
            at com.sun.jersey.server.impl.application.WebApplicationImpl.f(WebApplicationImpl.java:795)
            Truncated. see log file for complete stacktrace
    >
    <Aug 20, 2015 5:37:47 PM BST> <Error> <Deployer> <BEA-149202> <Encountered an exception while attempting to commit the 9
     task for the application "mdm_service-0.0.1-SNAPSHOT".>
    <Aug 20, 2015 5:37:47 PM BST> <Warning> <Deployer> <BEA-149004> <Failures were detected while initiating deploy task for
     application "mdm_service-0.0.1-SNAPSHOT".>
    <Aug 20, 2015 5:37:47 PM BST> <Warning> <Deployer> <BEA-149078> <Stack trace for message 149004
    weblogic.application.ModuleException: com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does
    not contain any root resource classes.: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:1359)
            at com.sun.jersey.server.impl.application.WebApplicationImpl.access0(WebApplicationImpl.java:180)
            at com.sun.jersey.server.impl.application.WebApplicationImpl.f(WebApplicationImpl.java:799)
            at com.sun.jersey.server.impl.application.WebApplicationImpl.f(WebApplicationImpl.java:795)
            Truncated. see log file for complete stacktrace
    >

最后我发现需要在 weblogic.xml

中添加以下代码
    <?xml version="1.0" encoding="UTF-8"?>
    <weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-web-app 
               http://xmlns.oracle.com/weblogic/weblogic-web-app/1.7/weblogic-web-app.xsd">

        <library-ref>
            <library-name>jax-rs</library-name>
            <specification-version>2.0</specification-version>
            <exact-match>false</exact-match>
        </library-ref>

    </weblogic-web-app>

我们实际上遇到了同样的错误,而且我们没有使用 CXF,但是 WebLogic (12.1.3) 的嵌入式 Jersey 实现似乎试图从我们的应用程序中包含的 jackson 依赖项中加载一些东西,然后失败了并导致应用程序部署失败。

我们的解决方案是使用 http://cxf.547215.n5.nabble.com/jaxrs-cxf-deployment-issues-on-weblogic-12c-td5742398.html 的建议,即将以下内容添加到 weblogic.xml,这样 WebLogic 就不会尝试这样做:

    <prefer-application-resources>
        <resource-name>META-INF/services/*</resource-name>
    </prefer-application-resources>