Issue
In my Spring Boot project, a couple of REST API endpoints require a class whose initialization takes several minutes. Because of this, it takes several minutes to start the REST API.
Is it possible (using Spring Boot) to make so that these few endpoints are initialized asynchronously i.e. all other endpoints are initialized right away and REST API starts working and these endpoints are initialized whenever the class that they need is initialized and are simply not available to the user before that?
I tried looking into @Async
and other ways to make things asynchronous in Spring Boot, but that did not help.
I would really appreciate some help.
Solution
Try @Lazy
annotation. When it's applied to the spring component, it will be initialized on the first call.
Some resources:
Answered By - Petr Aleksandrov
Answer Checked By - Marilyn (JavaFixing Volunteer)