简体   繁体   中英

Conflict with Spring Framework and and Apache CXF dependencies - 'No Such Method'

I am trying to integrate some functionality into my software that requires Apache CXF Bundle (2.7.18) for making SOAP calls to a certain set of web services.

My pom.xml file looks like:

<dependency>
    <--This is the new dependency I am integrating into my software-->
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-bundle</artifactId>
    <version>2.7.18</version>
</dependency>

//other dependencies

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>4.3.3.RELEASE</version>
</dependency>

The project builds fine with Maven, but when I try loading the .WAR file into Wildfly, I receive the following stack trace:

Context initialization failed: java.lang.NoSuchMethodError: org.springframework.expression.spel.SpelParserConfiguration.<init>(Lorg/springframework/expression/spel/SpelCompilerMode;Ljava/lang/ClassLoader;)V
at org.springframework.context.expression.StandardBeanExpressionResolver.<init>(StandardBeanExpressionResolver.java:98)
at org.springframework.context.support.AbstractApplicationContext.prepareBeanFactory(AbstractApplicationContext.java:557)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:455)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
at io.undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:173)
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:195)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:100)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:82)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
at org.jboss.threads.JBossThread.run(JBossThread.java:320)

2017-03-20 14:27:45,076 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 340) MSC000001: Failed to start service jboss.undertow.deployment.default-server.default-host./p6pmtjsonresponse: org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./p6pmtjsonresponse: java.lang.NoSuchMethodError: org.springframework.expression.spel.SpelParserConfiguration.<init>(Lorg/springframework/expression/spel/SpelCompilerMode;Ljava/lang/ClassLoader;)V
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:85)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
    at org.jboss.threads.JBossThread.run(JBossThread.java:320)
Caused by: java.lang.NoSuchMethodError: org.springframework.expression.spel.SpelParserConfiguration.<init>(Lorg/springframework/expression/spel/SpelCompilerMode;Ljava/lang/ClassLoader;)V
    at org.springframework.context.expression.StandardBeanExpressionResolver.<init>(StandardBeanExpressionResolver.java:98)
    at org.springframework.context.support.AbstractApplicationContext.prepareBeanFactory(AbstractApplicationContext.java:557)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:455)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
    at io.undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:173)
    at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:195)
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:100)

Any idea what might be causing this? I am wondering if I should be excluding some transitive dependency or something like that? I am open to using a different framework other than CXF if that is possible as well.

I believe that the conflict is due to trying to use two frameworks which create conflicts.

Thanks in advance!

The spring-web dependency brings in the following Spring jars:

spring-aop-4.3.3.RELEASE.jar
spring-beans-4.3.3.RELEASE.jar
spring-context-4.3.3.RELEASE.jar
spring-core-4.3.3.RELEASE.jar
spring-expression-4.3.3.RELEASE.jar
spring-web-4.3.3.RELEASE.jar

Adding the cxf-bundle dependency results in the following Spring jars:

spring-aop-4.3.3.RELEASE.jar
spring-asm-3.0.7.RELEASE.jar         **
spring-beans-4.3.3.RELEASE.jar
spring-context-4.3.3.RELEASE.jar
spring-core-4.3.3.RELEASE.jar
spring-expression-3.0.7.RELEASE.jar  ** Replaced 4.3.3
spring-jms-3.0.7.RELEASE.jar         **
spring-tx-3.0.7.RELEASE.jar          **
spring-web-4.3.3.RELEASE.jar

As you can see, CXF uses Spring 3.0.7, and Spring 3.0 is not compatible with Spring 4.3.

You could try to explicitly add dependencies to force the all the Spring jar files to version 4.3.3, but I doubt that will work. Too many internal changes between Spring 3 and Spring 4.

I was able to get this to work by upgrading to CXF 3.1.10 and Spring 4.3.3 and then replacing CXF-Bundle with the individual dependencies I needed such as:

<dependency>
    <groupId>org.apache.wss4j</groupId>
    <artifactId>wss4j</artifactId>
    <version>2.1.8</version>
    <type>pom</type>
</dependency>

<dependency>
    <groupId>org.apache.wss4j</groupId>
    <artifactId>wss4j-ws-security-common</artifactId>
    <version>2.1.8</version>
</dependency>
<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-frontend-jaxws</artifactId>
    <version>3.1.10</version>
</dependency>
<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-transports-http</artifactId>
    <version>3.1.10</version>
</dependency>
<!-- Jetty is needed if you're are not using the CXFServlet -->
<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-transports-http-jetty</artifactId>
    <version>3.1.10</version>
</dependency>

与cxf 2.xx相比,cxf 3.xx的类名和程序包名称有很多更改。在我们的项目中,spring 4.1.6.RELEASE与cxf 2.7.x配合良好

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM