我在根上下文(ApplicationContext)中有一个Bean,它自动将另一个Bean绑定到WebContext中,并抛出:
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。
最佳答案
子上下文可以在父上下文中访问Bean,但是父上下文不能在子上下文中访问Bean。
有关更多信息,请参见Spring Reference。
关于java - 无法从根上下文自动连线子Bean(在Web上下文中定义),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3722203/