I have a project where I have an interface, an Abstract class implementing the same interface and then a set of concrete classes which implement this interface and extend the Abstract Class.
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
public void write() { /* implementation.....*/}
}
Spring file has a component scan for the package.
<context:annotation-config>
<context:component-scan base-package="com.xyz" />
I am using a factory to get an instance of TypeAInvoice
invoice
Now calling invoice.process()
gets a NPE when getting to write.write()
I am not sure what am I missing here. I tried to see the component scan and scope and could not find anything conceptually wrong.