Java 自动布线抽象组件
我有一个原型bean工厂(Java 自动布线抽象组件,java,spring,Java,Spring,我有一个原型bean工厂(CreateCarAction是Springbean,scope=prototype): 我像这样自动连线: @Autowired @Qualifier("createCarActionFactory") private CreateCarActionFactory createCarActionFactory; 当我从CreateCarActionFactory中删除摘要时,它会起作用。当我删除抽象时,我必须实现createCarAction()-我不需要这个实现,
CreateCarAction
是Springbean,scope=prototype):
我像这样自动连线:
@Autowired
@Qualifier("createCarActionFactory")
private CreateCarActionFactory createCarActionFactory;
当我从CreateCarActionFactory
中删除摘要时,它会起作用。当我删除抽象时,我必须实现createCarAction()-我不需要这个实现,因为@Lookup会覆盖它。当我从CreateCarActionFactory
辞职时,我必须访问CreateCarAction
表单beanFactory,所以我选择了Autowire beanFactory,它也很难看
我可以自动连线抽象
CreateCarActionFactory
@Component
您可以autowire
一个接口,所以将CreateCarActionFactory从抽象类更改为接口。为什么不使用提供程序<代码>提供者createCarActionProvider代码>然后您只需执行createCarActionProvider.get()
。您无法自动连接抽象类-hya-我不明白,这种提供程序的实现在哪里?它将如何使用Autowired2Springbeans创建新类?这就是我使用Lookup..NoSuchBeanDefinitionException的原因:找不到[mypackage.CreateCarActionFactory]类型的符合依赖项条件的bean:至少需要1个符合此依赖项autowire候选项条件的bean。依赖项注释:{@org.springframework.beans.factory.annotation.Autowired(required=true)}
@Autowired
@Qualifier("createCarActionFactory")
private CreateCarActionFactory createCarActionFactory;