3

I want to be able to use my repositories in flyway java migration file. Here's my migration file

@Component
public class V1_2__Insert_Data implements SpringJdbcMigration {

    @Autowired
    private MyRepository myRepository;

    @Override
    public void migrate(JdbcTemplate jdbcTemplate) throws Exception {
         //logic goes here
    }
}

But Spring doesn't inject the repository to the bean. When I pass it as constructor argument, it crashes, because Flyway tries to invoke a non-args constructor. How can I do this?

Versions

flyway -> 5.0.5

spring-boot -> 1.5.9.RELEASE

vcmkrtchyan
  • 2,536
  • 5
  • 30
  • 59
  • Possible duplicate of [Spring beans are not injected in flyway java based migration](https://stackoverflow.com/questions/34923868/spring-beans-are-not-injected-in-flyway-java-based-migration) – pvpkiran Jan 15 '18 at 09:11
  • but there are some workarounds, not an official configuration way. And one of the answers states that there is a way in Flyway 5, which is actually the reason I upgraded from 4 to 5, but don't find the way to do it – vcmkrtchyan Jan 15 '18 at 09:24

0 Answers0