Spring beans are not injected in flyway java based migration

前端 未结 4 1357
迷失自我
迷失自我 2020-12-08 22:13

I\'m trying to inject component of configuration properties in the flyway migration java code but it always null.

I\'m using spring boot with Flyway.



        
4条回答
  •  时光说笑
    2020-12-08 22:46

    If you are using deltaspike you can use BeanProvider to get a reference to your Class. Here is a DAO example, but it should work fine with your class too.

    Change your DAO code:

    public static UserDao getInstance() {
        return BeanProvider.getContextualReference(UserDao.class, false, new DaoLiteral());
    }
    

    Then in your migration method:

    UserDao userdao = UserDao.getInstance();
    

    And there you've got your reference.

    (referenced from: Flyway Migration with java)

提交回复
热议问题