Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

434
Views
How to initialize Spring bean at very beginning of Spring initialization?

I would like to use in my Spring Boot application flywaydb to update / initialize database from SQL alter files on initialization. Java code, that process Flywaydb, should be executed after Spring datasource is created (Flywaydb needs javax.sql.DataSource) BUT before application beans are initialized. I am aware of @DependsOn annotation bud I don't want to avoid to set this on all application beans.

Is there some way how to initialize specific bean in specified order?

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Just don't do anything special. Spring Boot has support for Flyway out-of-the-box. There are only 3 steps to take

  1. Add Flyway as a dependency
  2. Put your migration scripts in src/main/resources/db/migration
  3. Start your application

You don't need to add annotations, create beans or use callbacks. The Spring Team already thought of that.

about 4 years ago · Santiago Trujillo Report

0

If you want a bean callback to happen exactly once when the application is ready to start, all beans are ready and will not get called again when the context is refreshed then a good Spring Boot recipe is to use the ApplicationReadyEvent like this:

@EventListener(ApplicationReadyEvent.class)
public void onApplicationEvent(ApplicationReadyEvent event) {
  // do tasks that should happen once on startup
}
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!