我有一个原型(prototype) bean 工厂(CreateCarAction
是 spring bean,scope=prototype):
@Component("createCarActionFactory")
public abstract class CreateCarActionFactory {
@Lookup
public abstract CreateCarAction createCarAction();
}
然后我像这样 Autowiring 它:
@Autowired
@Qualifier("createCarActionFactory")
private CreateCarActionFactory createCarActionFactory;
当我从 CreateCarActionFactory
中删除抽象时它起作用。当我删除抽象时,我必须实现 createCarAction() - 我不需要这个实现,因为 @Lookup 覆盖了它。当我从 CreateCarActionFactory
辞职时,我必须从 beanFactory 访问 CreateCarAction
,所以我转向 Autowire beanFactory,它也很丑陋..
我可以 Autowiring 抽象 CreateCarActionFactory
@Component
吗?
最佳答案
您可以 Autowiring
接口(interface),因此将 CreateCarActionFactory 从抽象类更改为接口(interface)。
关于java - Autowiring 抽象组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42541949/