我在春季有一个关于自动布线订单和@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)到循环依赖解析。 –