Spring Boot - the best way to read data from database on startup

2510 views spring-boot

I would like to read data to List or Map from database on startup. Which is the best way to do it? The Spring Boot version is 5.

Is the below solution is good?

public class ApplicationStartup 
implements ApplicationListener<ApplicationReadyEvent> {

   * This event is executed as late as conceivably possible to indicate that 
   * the application is ready to service requests.
  public void onApplicationEvent(final ApplicationReadyEvent event) {

    // here your code ...



I'd like to storage data on static class, but I have doubt that is the best solution.

answered question

1 Answer


I don't quite understand what is your motive for doing so but for doing so you can create a bean using @Component and in that bean create a method with annotation @PostConstruct. you can do whatever you want in this method.

posted this

Have an answer?


Please login first before posting an answer.