(JAVA)Wildfly 10 CXF原生依赖模块问题

时间:2016-02-16 13:46:15

标签: java maven jboss cxf wildfly

我正在尝试从wildfly8迁移到wildfly10 ..就像我升级一些依赖项一样,如spring,hibernate和CXF ......但我对来自wildfly的CXF嵌入式模块有一些问题。 在野生蝇上我在CXF上的2.7.8版本到野生蝇10上的3.1.4。

这里是我的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>

此处为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>

用于webservice配置的beans.xml

    <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>

最后我的问题...... 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

此类引用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>

这个项目在Wildfly 8上的CXF 2.7.4上运行良好,当我尝试在wildfly 10上迁移并使用嵌入式CXF时会出现问题

Projet工作,如果我排除wildfly的模块并嵌入所有依赖项(maven范围编译而不是提供)

我认为问题是由于wildfly的模块配置不好造成的。

感谢您的时间,

问候,

2 个答案:

答案 0 :(得分:1)

在将JBoss 7迁移到Wildfly 10.1之间时,我遇到了同样的问题

  

无法链接org / apache / cxf / transport / servlet / CXFServlet,因为   java.lang.NoClassDefFoundError:   组织/ springframework的/上下文/ ApplicationListener

原因是模块org.apache.cxf.impl对模块org.springframework.spring没有可选的依赖性。

在下面的模块org.apache.cxf.impl中添加依赖项后,问题就消失了。

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

当然,有必要安装org.springframework.spring模块。 我的module.xml(jar和模块取决于你需要的)示例:

<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>

如果你错过任何一个然后得到异常的问题,但是对于你缺少的类 - 那么必须在弹簧模块定义中添加适当的jar。

第二个准备jboss-deployment-structure.xml,我看起来:

<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>

答案 1 :(得分:0)

您正在将应用程序部署到WildFly,您需要添加一个MANIFEST FILE来满足部署过程并告诉WildFly不要忽略org.apache.cxf类

在我们将端点归档文件部署到WildFly时,请记住在MANIFEST.MF文件中向org.apache.ws.security和org.apache.cxf模块添加依赖项(由于@InInterceptor注释)

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

查看此帖子Advanced JAX-WS Security with Wildfly step by step