How to execute jobs just after spring loads application context?

后端 未结 5 1488
萌比男神i
萌比男神i 2021-02-01 03:14

I want to run some jobs just after loading the Spring context but I do not know how to do this.
Do you have any idea how to do that?

5条回答
  •  被撕碎了的回忆
    2021-02-01 03:58

    Another possibility would be to register a listener to application context events (). Basically it's the same as skaffman's solution, just implement:

    org.springframework.context.ApplicationListener
    

    instead of Lifecycle. It has only one method instead of three. :-)

提交回复
热议问题