使用 Spring 3.1.如果我想检索一个带有原型范围的bean(即我每次都想要一个不同的类实例),是否可以在不使用ApplicationContextaware类的情况下检索bean? 这就是我目前的做法 @Component@Qualifier(
这就是我目前的做法
@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有一些相当sophosticated方法来实现你所追求的…请参阅spring文档:http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/beans.html#beans-factory-scopes-other-injection
在谷歌上搜索spring代理范围也抛出了一些结果……
