Eld*_*rry 6 java flyway spring-boot
从版本 6.* 开始,Flyway 支持将 Spring bean 注入到JavaMigration
已实现接口的 java 迁移文件中。这是我的例子:
@Component\npublic class V1_201809261821__some_migration extends BaseJavaMigration {\n\n @Autowired\n private SomeDAO someDAO;\n\n @Override\n public void migrate(Context context) throws Exception {\n someDAO.doSomething();\n }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n启动时,它抱怨:
\n\n***************************\nAPPLICATION FAILED TO START\n***************************\n\nDescription:\n\nThe dependencies of some of the beans in the application context form a cycle:\n\n v1_201809261821__some_migration (field private SomeDAO V1_201809261821__some_migration.someDAO)\n\xe2\x94\x8c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x90\n| someDAO (field private org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate someDAO.namedParameterJdbcTemplate)\n\xe2\x86\x91 \xe2\x86\x93\n| flywayInitializer defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]\n\xe2\x86\x91 \xe2\x86\x93\n| flyway defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]\n\xe2\x86\x91 \xe2\x86\x93\n| v1_201809261821__some_migration (field private SomeDAO V1_201809261821__some_migration.someDAO)\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x98\n
Run Code Online (Sandbox Code Playgroud)\n\n看来我不能JdbcTemplate
在 Java 迁移文件中使用,Flyway 的文档JdbcTemplate
显示我可以使用以下方法构建自己的文件Context
:
public void migrate(Context context) {\n new JdbcTemplate(new SingleConnectionDataSource(context.getConnection(), true))\n .execute("INSERT INTO test_user (name) VALUES (\'Obelix\')");\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n但不幸的是我无法控制SomeDAO
,它来自另一个我无法触及的模块。
相关版本:
\n\n飞行路线:6.0.6
春季启动:2.2.0
小智 0
没有查看堆栈,但我猜 Flyway 作为迁移工具不希望您在更改数据时结构化数据......
其他(非数据访问)服务被注入并可以使用。
您可以从上下文中获取数据库连接,然后使用 jdbc 模板对其进行更改。
归档时间: |
|
查看次数: |
1858 次 |
最近记录: |