spring 未定义名为“cxf”的 bean

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6696785/
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-09-08 04:34:41  来源:igfitidea点击:

No bean named 'cxf' is defined

springtomcatcxf

提问by Virtually Real

I am trying to setup a simple restful web application, using tomcat 6.0.32, cxf 2.4.1. Anytime I issue any call, I get back an exception "No bean named 'cxf' is defined", where cxf is my bus.

我正在尝试使用 tomcat 6.0.32、cxf 2.4.1 设置一个简单的 Restful Web 应用程序。每当我发出任何调用时,我都会收到一个异常“没有定义名为‘cxf’的 bean”,其中 cxf 是我的总线。

Looking at the application log, I can see the cxf instance is created, and cached.

查看应用程序日志,我可以看到创建并缓存了 cxf 实例。

================ APP LOG BEGIN======================

================ 应用程序日志开始======================

910 DEBUG - Creating shared instance of singleton bean 'cxf'

910 DEBUG - 创建单例 bean 'cxf' 的共享实例

910 DEBUG - Creating instance of bean 'cxf'

910 DEBUG - 创建 bean 'cxf' 的实例

1018 DEBUG - Eagerly caching bean 'cxf' to allow for resolving potential circular references

1018 DEBUG - 急切地缓存 bean 'cxf' 以允许解析潜在的循环引用

1031 DEBUG - Returning eagerly cached instance of singleton bean 'cxf' that is not fully initialized yet - a consequence of a circular reference

1031 DEBUG - 返回尚未完全初始化的单例 bean 'cxf' 的急切缓存实例 - 循环引用的结果

1034 DEBUG - Finished creating instance of bean 'cxf'

1034 DEBUG - 完成创建 bean 'cxf' 的实例

1035 DEBUG - Returning cached instance of singleton bean 'org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor'

1035 调试 - 返回单例 bean 'org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor' 的缓存实例

1035 DEBUG - Returning cached instance of singleton bean 'org.apache.cxf.bus.spring.Jsr250BeanPostProcessor'

1035 调试 - 返回单例 bean 'org.apache.cxf.bus.spring.Jsr250BeanPostProcessor' 的缓存实例

1035 DEBUG - Returning cached instance of singleton bean 'org.apache.cxf.bus.spring.BusExtensionPostProcessor'

1035 调试 - 返回单例 bean 'org.apache.cxf.bus.spring.BusExtensionPostProcessor' 的缓存实例

1035 DEBUG - Creating shared instance of singleton bean 'connection'

1035 DEBUG - 创建单例 bean 'connection' 的共享实例

1035 DEBUG - Creating instance of bean 'connection'

1035 DEBUG - 创建 bean 'connection' 的实例

1035 DEBUG - Eagerly caching bean 'connection' to allow for resolving potential circular references

1035 DEBUG - 急切地缓存 bean 'connection' 以允许解析潜在的循环引用

1052 DEBUG - Finished creating instance of bean 'connection'

1052 DEBUG - 完成创建 bean 'connection' 的实例

1052 DEBUG - Creating shared instance of singleton bean 'connectionService'

1052 DEBUG - 创建单例 bean 'connectionService' 的共享实例

1052 DEBUG - Creating instance of bean 'connectionService'

1052 DEBUG - 创建 bean 'connectionService' 的实例

1053 DEBUG - Eagerly caching bean 'connectionService' to allow for resolving potential circular references

1053 DEBUG - 急切地缓存 bean 'connectionService' 以允许解析潜在的循环引用

1053 DEBUG - Returning cached instance of singleton bean 'connection'

1053 DEBUG - 返回单例 bean 'connection' 的缓存实例

1053 DEBUG - Returning cached instance of singleton bean 'cxf'

1053 DEBUG - 返回单例 bean 'cxf' 的缓存实例

1121 DEBUG - Invoking init method 'create' on bean with name 'connectionService'

1121调试-在名为“connectionService”的bean上调用init方法“create”

1356 DEBUG - Finished creating instance of bean 'connectionService'

1356 调试-完成创建 bean 'connectionService' 的实例

1384 DEBUG fecycleProcessor with name 'lifecycleProcessor': using default [org.springframework.context.support.DefaultLifecycleProcessor@45d1c3cd]

1384 DEBUG fecycleProcessor 名称为“lifecycleProcessor”:使用默认值 [org.springframework.context.support.DefaultLifecycleProcessor@45d1c3cd]

1385 DEBUG - Returning cached instance of singleton bean 'lifecycleProcessor'

1385 调试-返回单例 bean 'lifecycleProcessor' 的缓存实例

1387 DEBUG - Returning cached instance of singleton bean 'cxf'

1387 调试-返回单例 bean 'cxf' 的缓存实例

1387 DEBUG - Returning cached instance of singleton bean 'cxf'

1387 调试-返回单例 bean 'cxf' 的缓存实例

1388 DEBUG - Invoking init method 'create' on bean with name 'connectionService'

1388 调试-在名为“connectionService”的 bean 上调用 init 方法“create”

1391 DEBUG - Finished creating instance of bean 'connectionService'

1391 调试-完成创建 bean 'connectionService' 的实例

1391 DEBUG - Unable to locate LifecycleProcessor with name 'lifecycleProcessor': using default [org.springframework.context.support.DefaultLifecycleProcessor@2c3299f6]

1391 调试 - 无法找到名为“lifecycleProcessor”的 LifecycleProcessor:使用默认值 [org.springframework.context.support.DefaultLifecycleProcessor@2c3299f6]

1391 DEBUG - Returning cached instance of singleton bean 'lifecycleProcessor'

1391 调试-返回单例 bean 'lifecycleProcessor' 的缓存实例

1391 DEBUG - Published root WebApplicationContext as ServletContext attribute with name [org.springframework.web.context.WebApplicationContext.ROOT]

1391 DEBUG - 发布根 WebApplicationContext 作为 ServletContext 属性,名称为 [org.springframework.web.context.WebApplicationContext.ROOT]

1391 INFO - Root WebApplicationContext: initialization completed in 1390 ms

1391 信息-根 WebApplicationContext:初始化在 1390 毫秒内完成

================ APP LOG END======================

================ 应用程序日志结束======================

But when a request comes in, it always fails saying it can't find the bean.

但是当一个请求进来时,它总是失败,说它找不到 bean。

===================== Tomcat (localhost) Log Begin ==================

==================== Tomcat (localhost) 日志开始 ==================

INFO: Initializing Spring root WebApplicationContext

信息:初始化 Spring 根 WebApplicationContext

Jul 14, 2011 8:57:03 AM org.apache.catalina.core.ApplicationContext log

2011 年 7 月 14 日上午 8:57:03 org.apache.catalina.core.ApplicationContext 日志

SEVERE: StandardWrapper.Throwable

严重:StandardWrapper.Throwable

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'cxf' is defined

org.springframework.beans.factory.NoSuchBeanDefinitionException: 没有定义名为“cxf”的 bean

at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:527)

at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1083)

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:274)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)

at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1079)

at org.apache.cxf.transport.servlet.CXFServlet.loadBus(CXFServlet.java:58)

at org.apache.cxf.transport.servlet.CXFNonSpringServlet.init(CXFNonSpringServlet.java:54)

at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)

at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:809)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)

at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:864)

at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)

at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1665)

at java.lang.Thread.run(Thread.java:662)

===================== Tomcat (localhost) Log End ==================

==================== Tomcat (localhost) 日志结束 ==================

The only thing I can think of is that the bean is inserted in one context, and is being retrieved from another, but can't validate this or find a way around it. Any help would be greatly appreciated.

我唯一能想到的是 bean 被插入到一个上下文中,并且正在从另一个上下文中检索,但无法对此进行验证或找到解决方法。任何帮助将不胜感激。

回答by ccppjava

From your error log, I assume you use Spring, if so, you will need to add following lines to your Spring Context XML:

从您的错误日志中,我假设您使用 Spring,如果是这样,您将需要将以下行添加到您的 Spring Context XML:

<import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-extension-xml.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>

Hope this helps.

希望这可以帮助。

回答by David Lizárraga

If someone needs the Spring Java Based Configuration for solving this problem, there are two options:

如果有人需要 Spring Java Based Configuration 来解决这个问题,有两种选择:

You can import the cxf.xml file into your Java Config class with:

您可以使用以下命令将 cxf.xml 文件导入 Java Config 类:

@ImportResource({ "classpath:META-INF/cxf/cxf.xml" })

Or you can define the bean programatically in your Java Configuration class with:

或者您可以在 Java Configuration 类中以编程方式定义 bean:

@Bean
public SpringBus cxf() {        
    return new SpringBus();
}

CXF + Spring Java Configuration class example.

CXF + Spring Java 配置类示例

回答by gcerkez

In case anybody else gets here and is using mulesoft esb. The problem is also present in this system. To fix the issue, add the following section before the definition of the flows.

以防其他人来到这里并使用 mulesoft esb。这个问题也存在于这个系统中。要解决此问题,请在流定义之前添加以下部分。

<spring:beans>
    <spring:import resource="classpath:META-INF/cxf/cxf.xml" />
    <spring:import resource="classpath:META-INF/cxf/cxf-extension-xml.xml" />
    <spring:import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
    <spring:bean class="org.apache.cxf.bus.spring.Jsr250BeanPostProcessor" /> 
    <spring:bean id="classname" name="classname" class="some.implemented.interface.path" />
</spring:beans>

回答by Amreen Hundekari

Add these dependencies in the pom file:

在 pom 文件中添加这些依赖项:

<dependency>
???<groupId>org.apache.cxf</groupId>
???<artifactId>cxf-rt-rs-extension-search</artifactId>
???<version>2.6.0</version>
</dependency>
<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-rs-extension-providers</artifactId>
    <version>3.0.1</version>
</dependency>

回答by Amin Aminian

Please check these steps in below:

请检查以下步骤:

1) lines mentioned in below should be included in your Spring Context XML:

1) 下面提到的行应该包含在你的 Spring Context XML 中:

<import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>

2) Web.xml should be configured as below:

2) Web.xml 应配置如下:

<context-param>
     <param-name>contextConfigLocation</param-name>
     <param-value>classpath*:cxf.xml</param-value>
</context-param>

3) Dependencies in below should be added inside your pom.xml:

3)下面的依赖项应该添加到你的 pom.xml 中:

<dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxrs</artifactId>
        <version>${cxf.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxws</artifactId>
        <version>${cxf.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-ws-security</artifactId>
        <version>${cxf.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-ws-policy</artifactId>
        <version>${cxf.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-rs-service-description</artifactId>
        <version>${cxf.version}</version>
    </dependency>

If all this didnt help you to solve your issue, the last step is to check your weblogic configuration, here are the steps you have to check on your weblogic server:

如果所有这些都没有帮助您解决问题,最后一步是检查您的 weblogic 配置,以下是您必须在 weblogic 服务器上检查的步骤:

  1. make sure you have define a machine to your server.
  2. you need to specify your server and machine for your deployment as below:
  1. 确保您已为服务器定义了一台机器。
  2. 您需要为部署指定服务器和机器,如下所示:

Weblogic app deployment

Weblogic 应用程序部署

I hope by checking all these steps your issue get solved.

我希望通过检查所有这些步骤,您的问题得到解决。

Cheers

干杯