我们使用@Configuration类来进行基于Java的Spring配置.我正在尝试设置AnnotationConfigApplicationContext(s)的层次结构.
它似乎工作.因为我可以从父上下文中自动将bean作为从其中一个子上下文创建的bean的成员.
但是我没有管理从父上下文到@Configuration类文件的自动装配bean ,这非常方便.它们都是空的.
// parent context config
@Configuration
public class ParentContextConfig{
@Bean parentBeanOne...
@Bean parentBeanTwo...
}
Run Code Online (Sandbox Code Playgroud)
// child context config
@Configuration
public class ChildContextConfig{
@Autowired parentBeanOne
@Bean childBeanOne...
}
Run Code Online (Sandbox Code Playgroud)
// a sample bean
@Component
public class ChildBeanOne{
@Autowired parentBeanTwo
}
Run Code Online (Sandbox Code Playgroud)
在这个示例中,我得到的是parentBeanTwo正确创建的,而parentBeanOne不是autowired(null)到配置文件.
我错过了什么?
| 归档时间: |
|
| 查看次数: |
3055 次 |
| 最近记录: |