Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

435
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda