spring注解@postConstruct与constructor与@Autowired的启动顺序

 

本文链接:https://blog.csdn.net/zpflwy1314/article/details/80797756

       @Postcontruct’在依赖注入完成后自动调用,例如要将对象a注入到对象b中,首先需要生成对象a才能将a注入到b中,所以一个类中只有成员变量a被Autowired注入是发生在A的构造方法完成之后的,如果在生成对象时完成某些被初始化操作,而这个有依赖与依赖注入。@postConstruct与constructor与@Autowired的启动顺序:

为constructor(构造方法)——>@Autowired——>@postConstruct   

还有一个加载的方法就是实现InitializingBean接口其中重写afterPropertiesSet()方法,这个方法在@postConstruct方法之后运行,还有另外一个方法就是init-mathod方法该方法在afterPropertiesSet()方法之后运行,总结之后的顺序为:

constructor(构造方法)——>@Autowired——>@postConstruct——>afterPropertiesSet()àinit-method——》init-mathod

原文地址:https://www.cnblogs.com/kelelipeng/p/11815244.html