I am trying to autowire multiple services (around 10-15) in a class having static methods and came across a solution mentioned in this post about using @Autowired
constructor. Can we use constructor @Autowired approach for multiple classes as well?
For example, suppose I have two classes Foo1
and Foo2
. Can I use the single constructor for both classes like
@Component
public class Boo {
private static Foo1 foo1;
private static Foo2 foo2;
@Autowired
public Boo(Foo1 foo1, Foo2 foo2) {
Boo.foo1 = foo1;
Boo.foo2 = foo2;
}
public static void randomMethod() {
foo1.doStuff();
foo2.doSomeOtherStuff();
}
}
Or is there any other way to achieve this ?