If I have two classes like:
Class A {
public String importantValue = "stringvalue";
@Autowire
public B b;
}
@Component
@Scope("prototype");
Class B {
// This should be set automatically
// from IOC Container upon injection.
public String importantValueFromA;
}
Is this even possible? As soon as B class has been injected to A it should automatically set the value in B.
Do you want class
Ato do some setup on injected classB? That’s simple:Obviously you cannot access
b.importantValueFromAinA.Aconstructor because injection didn’t yet happen. But@PostConstructcallback is guaranteed to be called after injection.Another approach is to use setter injection, but it feels kind of hacky:
Two suggestions:
privateand use setters/methods to access them.Bwill be created.