First time using Java, and first time using Spring I have an issue with the DI, I tried this and this is works:
public interface MyInterface {
void someMethod();
}
@Component
public class A implements MyInterface {
public void someMethod() { }
}
@Component
public class B implements MyInterface {
public void someMethod() { }
}
@Component
public class MyMain {
public MyMain(@Autowired LinkedList<MyInterface> y) { }
}```
I can run over y and I will have A & B
But for some reason when I try to do this:
public interface MyInterface {
void someMethod();
}
public abstract class MyAbstractClass implements MyInterface { }
@Component
public class A extends MyAbstractClass {
@Override
public void someMethod() { }
}
@Component
public class B extends MyAbstractClass {
@Override
public void someMethod() { }
}
@Component
public class MyMain {
public MyMain(@Autowired LinkedList<MyInterface> y) { }
}```
y is empty, I tried to debug and it seems it first creates MyMain in the second, in the first example it MyMain is created after all of MyInterface implementations.
How can I fix this so the second example will work?