我在春季有一個關於自動佈線訂單和@PostConstruct
邏輯的問題。例如下面的演示代碼,我有一個主彈簧引導類:春季自動裝配訂單和@PostConstruct
@SpringBootApplication
public class Demo1Application {
@Autowired
BeanB beanb;
public static void main(String[] args) {
SpringApplication.run(Demo1Application.class, args);
}
}
和2 @Service
定義:
@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();
}
}
,我有以下的輸出:
豆被稱爲
打印我在Bean B中調用
beanb被稱爲
我的問題是自動裝配是如何發生的一步一步像上面的場景?
以及如何printMe()
方法beanb
被調用,而不是先調用其@PostConstruct
?
[鏈接](https://docs.spring.io/spring/docs/4.1.x/spring-framework-reference/html/beans。 html#beans-dependency-resolution)到循環依賴解析。 –