Skip to content

Database migrations may not have run before NamedParameterJdbcTemplate is used #16032

@xak2000

Description

@xak2000

This is a variation of already fixed issue with JdbcTemplate #13155. But this is for NamedParameterJdbcTemplate.

The fix (4881925) doesn't take into account another kind of JdbcTemplate - NamedParameterJdbcTemplate, which implements NamedParameterJdbcOperations (and doesn't implement JdbcOperations).

So, if an application doesn't create JdbcTemplate bean but only creates NamedParameterJdbcTemplate bean (using it's NamedParameterJdbcTemplate(DataSource dataSource) constructor), this bean still created before migration tool (e.g. Flyway) runs their migrations. So any @PostConstruct, that uses NamedParameterJdbcTemplate, runs earlier than migration. What is worse: there is not always the case. Sometimes migrations runs earlier. I think this is more or less "random" order because there is no explicit @DependsOn here.

So I think it's need to create a NamedParameterJdbcOperationsDependsOnPostProcessor in line with JdbcOperationsDependsOnPostProcessor and Flyway/Liqbase childs of it.

Spring Boot version tested: 2.0.5. But I don't see any NamedParameterJdbcOperations postprocessors in master, so I think this bug affects current version too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: supersededAn issue that has been superseded by anothertype: bugA general bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions