相关疑难解决方法(0)

在基于flyway java的迁移中不会注入Spring bean

我试图在flyway迁移java代码中注入配置属性的组件,但它总是为null.

我和Flyway一起使用弹簧靴.

@Component
@ConfigurationProperties(prefix = "code")
public class CodesProp {

    private String codePath;
 }
Run Code Online (Sandbox Code Playgroud)

然后在Flyway迁移代码中,尝试按如下方式自动执行此组件:

public class V1_4__Migrate_codes_metadata implements SpringJdbcMigration {

@Autowired
private CodesProp codesProp ;
public void migrate(JdbcTemplate jdbcTemplate) throws Exception {
    codesProp.getCodePath();  
}
Run Code Online (Sandbox Code Playgroud)

在这里,codesProp始终为null.

有没有办法在飞路中注入弹簧豆或在飞路豆之前进行初始化?

谢谢.

spring flyway spring-boot

13
推荐指数
2
解决办法
8193
查看次数

Flyway的Java迁移文件中使用JdbcTemplate导致依赖循环

从版本 6.* 开始,Flyway 支持将 Spring bean 注入到JavaMigration已实现接口的 java 迁移文件中。这是我的例子:

\n\n
@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 …
Run Code Online (Sandbox Code Playgroud)

java flyway spring-boot

6
推荐指数
1
解决办法
1858
查看次数

Flyway 6 JavaMigrations 与 Spring Beans 的本机依赖注入

我见过许多很棒的解决方法来创建 Flyway JavaMigrations 并使用@DependsOn和注入 Spring Bean ApplicationContextAware(例如/sf/answers/3377000581/)。

然而,Flyway 6 文档的一部分声称 Spring Bean 本身可以进行依赖注入:

是真的吗?这将如何运作?

dependency-injection flyway spring-data spring-boot

2
推荐指数
1
解决办法
1766
查看次数