Spring autowiring order und @ PostConstruct
Ich habe eine Frage zur Reihenfolge der automatischen Verkabelung und@PostConstruct
Logik im Frühjahr. Zum Beispiel habe ich folgenden Demo-Code für eine Spring Boot-Hauptklasse:
@SpringBootApplication
public class Demo1Application {
@Autowired
BeanB beanb;
public static void main(String[] args) {
SpringApplication.run(Demo1Application.class, args);
}
}
und 2@Service
Definitionen:
@Service
public class BeanB {
@Autowired
private BeanA beana ;
@PostConstruct
public void init(){
System.out.println("beanb is called");
}
public void printMe(){
System.out.println("print me is called in Bean B");
}
}
@Service
public class BeanA {
@Autowired
private BeanB b;
@PostConstruct
public void init(){
System.out.println("bean a is called");
b.printMe();
}
}
und ich habe die folgende Ausgabe:
bean a heißt
print me heißt in Bean B
beanb heißt
Meine Frage ist, wie Autowiring wie in einem obigen Szenario schrittweise abläuft?
Und wieprintMe()
Methode vonbeanb
wird aufgerufen, ohne sein @ aufzuruf@PostConstruct
zuerst