2010-09-15 57 views
1

我在這autowires另一個bean在WebContext根上下文(ApplicationContext的)一個bean和它拋出:不能自動裝配從根上下文子bean(在Web上下文定義)

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在根上下文中定義,在Web上下文中定義MessageTemplate。

+1

那麼我怎麼能解決這個問題?我需要通過PageFlowController發送一條Flex消息,並且我需要PageFlowController來共享,因爲有Restful控制器的另一個Web上下文。 – einundswanzig 2010-09-17 15:20:46

回答

4

子上下文有權訪問父上下文中的bean,但父上下文無法訪問子上下文中的bean。

查看Spring Reference瞭解更多信息。