【发布时间】:2020-02-18 05:59:19
【问题描述】:
从版本 6.* 开始,Flyway 支持 Spring bean 注入 java 迁移文件,实现了JavaMigration 接口。这是我的例子:
@Component
public class V1_201809261821__some_migration extends BaseJavaMigration {
@Autowired
private SomeDAO someDAO;
@Override
public void migrate(Context context) throws Exception {
someDAO.doSomething();
}
}
启动时报错:
***************************
APPLICATION FAILED TO START
***************************
Description:
The dependencies of some of the beans in the application context form a cycle:
v1_201809261821__some_migration (field private SomeDAO V1_201809261821__some_migration.someDAO)
┌─────┐
| someDAO (field private org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate someDAO.namedParameterJdbcTemplate)
↑ ↓
| flywayInitializer defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]
↑ ↓
| flyway defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]
↑ ↓
| v1_201809261821__some_migration (field private SomeDAO V1_201809261821__some_migration.someDAO)
└─────┘
似乎我不能在Java迁移文件中使用JdbcTemplate,Flyway's document表明我可以使用Context构造自己的JdbcTemplate,例如:
public void migrate(Context context) {
new JdbcTemplate(new SingleConnectionDataSource(context.getConnection(), true))
.execute("INSERT INTO test_user (name) VALUES ('Obelix')");
}
但不幸的是我无法控制SomeDAO,它来自另一个我无法触摸的模块。
相关版本:
航路:6.0.6
Spring Boot:2.2.0
【问题讨论】:
-
您遇到过这个问题吗?还是您找到任何解决方法,我遇到了完全相同的问题。
-
@FolgerFonseca 我通过找到修改
SomeDAO的方法解决了这个问题,这打破了问题设置的限制......
标签: java spring-boot flyway