3

I just tried to run a simple web service application with Apache CXF and Spring by Maven, but I got the following error when I started Tomcat:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cxf' defined in class path resource [META-INF/cxf/cxf.xml]: Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: org.springframework.context.support.AbstractApplicationContext.addApplicationListener(Lorg/springframework/context/ApplicationListener;)V
Caused by: java.lang.NoSuchMethodError: org.springframework.context.support.AbstractApplicationContext.addApplicationListener(Lorg/springframework/context/ApplicationListener;)V
    at org.apache.cxf.bus.spring.SpringBus.setApplicationContext(SpringBus.java:78)
    at org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:86)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:296)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:843)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:419)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:241)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:152)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:199)
    at org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:661)
    at org.springframework.context.support.AbstractApplicationContext.registerListeners(AbstractApplicationContext.java:505)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:328)
    at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:155)
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:246)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:184)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4205)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4704)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
    at org.apache.catalina.core.StandardService.start(StandardService.java:525)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

Is there any way to resolve this error?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Tino M Thomas
  • 1,676
  • 2
  • 16
  • 24

5 Answers5

3

You probably have multiple versions of Spring (2.5.6 vs 3.0 or 3.1) on the classpath. Check your Maven dependencies.

artbristol
  • 32,010
  • 5
  • 70
  • 103
3

Couple of options:

1) Update to Spring 3.x - it looks like you are using 2.5.x.

2) Update to the latest releases of CXF released last week. CXF SHOULD still work with spring 2.5.x (but likely not for much longer), but an errant commit caused the 2.5.2 to no longer work with 2.5.x. This was fixed for 2.6/2.5.3.

Daniel Kulp
  • 14,447
  • 4
  • 45
  • 37
0

I had that same problem when trying to use cxf with Camel.

But it occurred because I added old cxf-rt-ws-security module that had dependency on older cxf than my camel-cxf had. Make sure you have common version for all cxf modules.

fizmax
  • 497
  • 5
  • 11
0

I had similar issue where I had my Spring context available inside the lib folder of my war and its transitive dependency such as cxf-rt-ws-policy, cxf-core was kept in tomcat lib folder.

Moving cxf-rt-ws-policy and cxf-core to the war's lib folder solved the issue.

vsriram92
  • 593
  • 1
  • 4
  • 15
0

In my case the root cause was, that I had cxf:bus in clients.xml

    <cxf:bus>
        <cxf:features>
            <bean class="org.apache.cxf.ext.logging.LoggingFeature"/>
        </cxf:features>
    </cxf:bus>

but I had CXF:Bus bean created on other places.

walter33
  • 776
  • 5
  • 12