java 使用在类路径资源 META-INF/cxf/cxf.xml 中定义的名称“cxf”创建 bean 时出错

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10276054/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 00:21:02  来源:igfitidea点击:

Error creating bean with name 'cxf' defined in class path resource META-INF/cxf/cxf.xml

javaweb-servicesspringmavencxf

提问by Tino M Thomas

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

我只是尝试使用 Apache CXF 和 spring by 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)

Is there any way to resolve this error? thanks in advance

有没有办法解决这个错误?提前致谢

采纳答案by artbristol

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

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

回答by Daniel Kulp

Couple of options:

几个选项:

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

1) 更新到 Spring 3.x - 看起来您使用的是 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.

2) 更新至上周发布的最新 CXF 版本。CXF 应该仍然适用于 spring 2.5.x(但可能不会持续太久),但是错误的提交导致 2.5.2 不再适用于 2.5.x。这已在 2.6/2.5.3 中修复。

回答by fizmax

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

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

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

但它发生是因为我添加了旧cxf-rt-ws-security模块,这些模块依赖于比我更旧的 cxf camel-cxf。确保所有 cxf 模块都有通用版本。