在类路径资源META-INF / cxf / cxf.xml中定义名为“cxf”的bean时出错

时间:2012-04-23 06:55:45

标签: java web-services spring maven cxf

我只是尝试使用Apache CXF和Maven运行一个简单的Web服务应用程序 ,但是当我启动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)

有什么办法可以解决这个错误吗?提前谢谢

3 个答案:

答案 0 :(得分:2)

你可能在类路径上有多个版本的Spring(2.5.6 vs 3.0或3.1)。检查您的Maven依赖项。

答案 1 :(得分:2)

几个选项:

1)更新到Spring 3.x - 看起来你正在使用2.5.x。

2)更新上周发布的最新版CXF。 CXF应该仍然可以使用spring 2.5.x(但可能不会更长),但错误的提交导致2.5.2不再适用于2.5.x.这是固定的2.6 / 2.5.3。

答案 2 :(得分:0)

尝试将cxf与Camel一起使用时遇到了同样的问题。

但之所以发生这种情况,是因为我添加了旧的cxf-rt-ws-security模块,该模块依赖于较旧的cxf,而不是camel-cxf。确保所有cxf模块都有通用版本。