Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

436
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda