无法从根上下文自动装配子bean(在Web上下文中定义)

时间:2010-09-15 22:03:40

标签: java spring

我在根上下文(ApplicationContext)中有一个bean,它在WebContext中自动装配另一个bean并且它正在抛出:

Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pageFlowController': Injection of autowired dependencies failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.flex.messaging.MessageTemplate
com.biosds.gcfs.nassic.flow.PageFlowController.msgTemplate; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type
[org.springframework.flex.messaging.MessageTemplate] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: 
{@org.springframework.beans.factory.annotation.Autowired(required=true)}

我正在尝试在PageFlowController中获取MessageTemplate,其中PageFlowController在根上下文中定义,而MessageTemplate在Web上下文中定义。

1 个答案:

答案 0 :(得分:4)

子上下文可以访问父上下文中的bean,但父上下文无权访问子上下文中的bean。

有关详细信息,请参阅Spring Reference