(JAVA) Wildfly 10 CXF native dependency module issues

依然范特西╮ 提交于 2019-12-11 02:13:20

问题


I'm trying to migrate from wildfly8 to wildfly10 .. by the same way i'm upgrade some dependency like spring,hibernate and CXF ... but i have some issue with CXF embedded module from wildfly. on wildfly i was on 2.7.8 version on CXF to 3.1.4 on wildfly 10.

here my pom.xml

    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxws</artifactId>
        <version>${cxf.version}</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http</artifactId>
        <version>${cxf.version}</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-ws-security</artifactId>
        <version>${cxf.version}</version>
        <scope>provided</scope>
    </dependency>

    <!-- jaxrs is not in wildfly embedded module -->
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxrs</artifactId>
        <version>${cxf.version}</version>
        <scope>compile</scope>
        <!-- 
        <exclusions>
            <exclusion>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-api</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-bindings-xml</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-core</artifactId>
            </exclusion>
        </exclusions>
         -->
    </dependency>

here jboss-deployment-structure.xml

<deployment>
    <dependencies>
        <module name="org.apache.cxf" export="true">
            <imports>
                <include path="META-INF**" />
                <include path="META-INF/cxf**" />
            </imports>
        </module>

        <module name="org.apache.cxf.impl" export="true">
            <imports>
                <include path="META-INF**" />
                <include path="META-INF/cxf**" />
            </imports>
        </module>
    </dependencies>
</deployment>

beans.xml for webservice configuration

    <import resource="classpath:META-INF/cxf/cxf.xml" /> 
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> 
    <import resource="classpath:META-INF/cxf/cxf-extension-*.xml" />
    <import resource="classpath:META-INF/cxf/**.xml" />
    <bean id="restService" class="com.itoptics.epcmobilereader.webservice.WebService" />
    <bean id="authenticationInterceptor"
class="com.itoptics.epcmobilereader.interceptor.PolicyAuthenticationInterceptor">
    </bean>
    <bean id="authorizationQueryInterceptor"class="org.apache.cxf.interceptor.security.SimpleAuthorizingInterceptor">
        <property name="methodRolesMap">
            <map>
                <entry key="autorisation" value="ROLE_CUSTOMER" />
            </map>
        </property>
    </bean>
    <jaxrs:server id="resteProService" address="/EasyCaseEPC">
        <jaxrs:serviceBeans>
            <ref bean="restService" />
        </jaxrs:serviceBeans>
        <jaxrs:providers>
            <bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" />
        </jaxrs:providers>
     <jaxrs:inInterceptors>
            <ref bean="authenticationInterceptor" />
        </jaxrs:inInterceptors> 
    </jaxrs:server>

And finally my issue .... NoClassDefFoundError

Caused by: java.lang.NoClassDefFoundError: Failed to link org/apache/cxf/transport/servlet/CXFServlet (Module "org.apache.cxf.impl:main" from local module loader @33e5ccce (finder: local module finder @5a42bbf4 (roots: /home/xxx/Desktop/wildfly-10.0.0.Final/modules,/home/xxx/Desktop/wildfly-10.0.0.Final/modules/system/layers/base))): org/springframework/context/ApplicationListener

This class refer to web.xml

<servlet>
    <servlet-name>CXFServlet</servlet-name>
    <display-name>CXF Servlet</display-name>
    <servlet-class>
        org.apache.cxf.transport.servlet.CXFServlet
    </servlet-class>
    <load-on-startup>2</load-on-startup>
</servlet>

This projet worked fine on CXF 2.7.4 on wildfly 8 , the problem happen when I tried to migrate on wildfly 10 and using CXF embedded

Projet work if I exclude wildfly's module and embeds all dependencies ( maven scope compile instead provided )

I suppose the problem is due to a bad wildfly's module configuration.

Thanks for your time,

Regards,


回答1:


I had exactly this same problem when migrate app between JBoss 7 to Wildfly 10.1

Failed to link org/apache/cxf/transport/servlet/CXFServlet because java.lang.NoClassDefFoundError: org/springframework/context/ApplicationListener

The reason of this is that the module org.apache.cxf.impl hasn't optional dependency on module org.springframework.spring.

After adding dependency in module org.apache.cxf.impl like below the problem disappeared.

<module name="org.springframework.spring" optional="true">
    <imports>
        <include path="META-INF"/>
    </imports>
</module>

Of course, it is necessary to install org.springframework.spring module. My module.xml (jars and modules depends on what you need) example:

<module xmlns="urn:jboss:module:1.1" name="org.springframework.spring">
    <resources>
        <resource-root path="aopalliance-1.0.jar"/>
        <resource-root path="aspectjweaver-1.6.8.jar"/>
        <resource-root path="cglib-2.2.2.jar"/>
        <resource-root path="spring-aop-3.1.0.RELEASE.jar"/>
        <resource-root path="spring-asm-3.1.0.RELEASE.jar"/>
        <resource-root path="spring-beans-3.1.0.RELEASE.jar"/>
        <resource-root path="spring-context-3.1.0.RELEASE.jar"/>
        <resource-root path="spring-context-support-3.1.0.RELEASE.jar"/>
        <resource-root path="spring-core-3.1.0.RELEASE.jar"/>
        <resource-root path="spring-expression-3.1.0.RELEASE.jar"/>
        <resource-root path="spring-jdbc-3.1.0.RELEASE.jar"/>
        <resource-root path="spring-orm-3.1.0.RELEASE.jar"/>
        <resource-root path="spring-tx-3.1.0.RELEASE.jar"/>
        <resource-root path="spring-web-3.1.0.RELEASE.jar"/>
    </resources>
    <dependencies>
        <module name="javax.api"/>
        <module name="javax.mail.api" />
        <module name="javax.faces.api"/>
        <module name="javax.jms.api"/>
        <module name="javax.annotation.api"/>
        <module name="javax.persistence.api"/>
        <module name="javax.activation.api"/>
        <module name="javax.servlet.api"/>
        <module name="org.apache.commons.logging"/>
        <module name="org.jboss.vfs"/>
        <module name="org.hibernate"/>
        <module name="org.hibernate.validator"/>
        <module name="org.hibernate.commons-annotations"/>
        <module name="asm.asm"/>
    </dependencies>
</module>

If you miss any then get exception like in question but for your missing class - then have to add proper jar to spring module definition.

And second prepare jboss-deployment-structure.xml, my look that:

<jboss-deployment-structure>
    <deployment>
        <dependencies>
            <module name="org.apache.cxf" export="true">
                <imports>
                    <include path="META-INF**"/>
                    <include path="META-INF/cxf**"/>
                </imports>
                <exports>
                    <include path="META-INF"/>
                    <include path="META-INF/cxf"/>
                </exports>
            </module>
            <module name="org.apache.cxf.impl" export="true">
                <imports>
                    <include path="META-INF**"/>
                    <include path="META-INF/cxf**"/>
                </imports>
                <exports>
                    <include path="META-INF"/>
                    <include path="META-INF/cxf"/>
                </exports>
            </module>
            <module name="org.apache.commons.io"/>
            <module name="org.apache.commons.codec"/>
            <module name="org.apache.commons.lang"/>
            <module name="org.apache.commons.beanutils"/>
            <module name="org.apache.commons.collections"/>
            <module  name="org.springframework.spring" export="true" >
                <imports>
                    <include path="META-INF**"/>
                </imports>
                <exports>
                    <include path="META-INF"/>
                </exports>
            </module>
            <module name="org.apache.xerces"/>
            <module name="org.apache.xalan"/>
            <module name="org.slf4j"/>
        </dependencies>
    </deployment>
</jboss-deployment-structure>



回答2:


Sofar that you are deploying your application to WildFly you need to add a MANIFEST FILE to satisfy the deployment process and tell WildFly to not ignore org.apache.cxf classes

As we're deploying the endpoint archive to WildFly, remember to add a dependency to org.apache.ws.security and org.apache.cxf module (due to the @InInterceptor annotation) in the MANIFEST.MF file.

Manifest-Version: 1.0
Built-By: Festus TAMAKLOE (FESTADO IT CONSULTING)
Ant-Version: Apache Ant 1.7.1
Build-Jdk: 1.8.0_92
Dependencies: org.apache.ws.security,org.apache.cxf

look at this post Advanced JAX-WS Security with Wildfly step by step



来源:https://stackoverflow.com/questions/35434293/java-wildfly-10-cxf-native-dependency-module-issues

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!