【发布时间】:2013-01-04 11:27:08
【问题描述】:
使用 Spring 3.1。如果我想检索具有原型范围的 bean(即我每次都想要一个不同的类实例),是否可以在不使用 ApplicationContextaware 类的情况下检索 bean?
我目前是这样的
@Component
@Qualifier("MyService")
public class MyServiceImpl implements MyService {
@Override
public void doSomething() {
Blah blah = (Blah)ApplicationContextProvider.getContext().getBean("blah");
blah.setThing("thing");
blah.doSomething();
}
}
@Component("blah")
@Scope("prototype")
public class Blah {
....
}
ApplicationContextProvider 实现 ApplicationContextAware 的地方。
是否可以通过注解或简单的 Spring 配置来做到这一点,而不必使用 ApplicationContextAware 类?
【问题讨论】:
标签: spring dependency-injection