Skip to content

Database migrations may not have run before JdbcTemplate is used #13155

Closed
@MatanRubin

Description

@MatanRubin

Using Spring Boot 2.0.2.RELEASE I set up a simple project that uses Flyway for migrations and JDBC template for accessing the DB. I expect all Flyway migrations to finish running before I can use the datasource. However, I noticed that PostConstruct runs before Flyway migrations. That means I access the old version of the schema, causing application failures.

As mentioned here, one may annotate the component that uses JdbcTemplate with: @DependsOn({"flyway", "flywayInitializer"}), but this is cumbersome and error prone - it is easy to forget to do so, and I don't see a reason this shouldn't be the default behaviour.

The attached project is a minimal Spring Boot application with a single component that uses the database in its PostConstruct method. The output shows that PostConstruct is called before Flyway runs.

demo-4.zip

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions