【发布时间】:2011-06-16 17:22:02
【问题描述】:
我的课堂上有以下代码
public void startListeners() throws Exception {
List<QueueConfiguration> queueConfigs = queueConfigResolver.getQueueConfigurations();
for(QueueConfiguration queueConfig : queueConfigs){
//TODO : work on this make it more testable
ICustomListener readerListener = new MyCustomListener(queueConfig);
readerListeners.add(readerListener);
readerListener.start();
}
}
我正在使用 Spring 进行依赖注入(不是在这种情况下,而是总体而言)。现在这段代码有两个问题。
- 我无法在测试时为创建的每个侦听器进行模拟。
- 我不想使用 ApplicationContext.getBean() 因为它会产生同样的影响。 AFAIK spring 无法动态执行此操作,但还有其他指针吗?
【问题讨论】:
-
你能更详细地解释一下你到底想测试什么吗? queueConfiguration 还是监听器?为什么你不想完全使用 applicationcontext.getbean? Spring 不能动态地做什么。在这种情况下,动态意味着什么?
标签: spring dynamic dependency-injection