Will a method annotated with @PostConstruct be guaranteed to execute prior to a method with @Scheduled within the same bean?

前端 未结 1 1699
故里飘歌
故里飘歌 2021-01-21 09:18

Say I\'m defining a caching bean which will be initialized upon launch of the application and will be refreshed at a fixed interval as seen below:

@Component
pub         


        
相关标签:
1条回答
  • 2021-01-21 09:39

    Yes, the method annotated with @PostConstruct is guaranteed to execute first.

    The @Scheduled annotation is activated by ScheduledAnnotationBeanPostProcessor.postProcessAfterInitialization() which is invoked after any bean initialization callbacks (like InitializingBean's afterPropertiesSet or a custom init-method).

    0 讨论(0)
提交回复
热议问题