我有一个项目,我有一个接口,一个实现相同接口的Abstract类,然后是一组实现此接口并扩展Abstract Class的具体类。Spring Autowiring不适用于抽象类
public interface Invoice
{
void process();
}
@component
public abstract class AbstractInvoice(){
@Resource
protected Writer writer;
protected validateInvoice(){
//some implementation
}
}
@Component
public Class TypeAInvoice() extends AbstractInvoice implements Invoice{
@Override
public void process(){
//... some code
writer.write();
}
}
public Interface Writer(){
public void write();
}
@Component
public class CDWriter implements Writer{
@Override
pubic void write(){ // implementation.....}
}
Spring文件具有包的组件扫描。
<context:annotation-config>
<context:component-scan base-package="com.xyz" />
我使用一个工厂来获得TypeAInvoice
发票 现在呼吁invoice.process()
的实例前往write.write()
时得到了NPE我不知道我是什么在这里失踪。我试图看到组件扫描和范围,并且在概念上找不到任何错误。
从'AbstractInvoice'中删除'@ component'注释并尝试。 – xyz
向我们展示如何获得TypeAInvoice的实例。 –