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?
If you want run a job after Spring's context start, then you can use the ApplicationListener and the event ContextRefreshedEvent .
ApplicationContext is a corner stone of a Spring Boot application. It represents the Spring IoC container and is responsible for instantiating, configuring, and assembling the beans. The container gets its instructions on what objects to instantiate, configure, and assemble by reading configuration metadata.
You can have two contexts within an application. If you have two contexts each will have its own singleton.
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<org.springframework.context.event.ContextRefreshedEvent>
instead of Lifecycle. It has only one method instead of three. :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With