How to inject correct implementation of a field in extended class from abstract??
Hi all!
I try to explain the subject of this message, I think with the tittle is not very clear :D.
I'm implementing some DAO stuff where I use an abstract class my other classes extend from. In this abstract class I have a property which type is an "abstract" interface I use as a model. Each class that extends this abstract class has its own interface which extends from the abstract interface. This way I can autowired the correct implementation of the interface for the field using @Autowired in the setter method for the property. The problem is I have to override the setter method in every class that extends from the abstract class to let spring know which implementation I want for each of them.
My question is, is there any way to set the @Autowired annotation in the abstract class so, when I extend this class, spring knows which implementation to wire to not to override the setter method in every class? I tried with generics but it doesn't work
It's a little bit complicated to explain so here is some code.
Code:
public interface AbstractInterface{
......
}
public class AbstractClass {
protected AbstractInterface property;
.... some code using property....
}
public interface ExtendedInterface extends AbstractInterface{
....
}
public class ExtendedClass extends AbstractClass {
//This is what I want to avoid
@Autowired
public void setProperty(ExtendedInterface propertyExtended){
this.property = propertyExtended;
}
}
Any suggestions?
Thanks in advance!!!