我有一个 Spring Boot 项目,其中 Flyway 与 JPA 一起使用。
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
该项目运行得非常好。由于一些要求,我不得不更改 Flyway 加载的顺序,以便它在 Hibernate 之后加载。我搜索并找到了以下解决方案https://stackoverflow.com/a/44806540/1361888
。我按照上述链接中的答案建议创建了 MigrationConfiguration
。现在,当我运行该应用程序时,它会给出以下错误,
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of method flywayInitializer in
com.x2iq.microservice.config.MigrationConfiguration required a bean of type
'org.flywaydb.core.Flyway' that could not be found.
Action:
Consider defining a bean of type 'org.flywaydb.core.Flyway' in your
configuration.
现在我对 Spring Boot 相当陌生,所以无法理解这个错误,并且我在网上找不到与此错误相关的任何内容。
最佳答案
在@Configuration
类中,您希望向容器公开一个Flyway Bean。像这样的事情应该可以解决问题:
@Configuration
public class MigrationConfiguration {
@Bean
public Flyway flyway(){
return new Flyway();
}
}
关于java - 考虑定义一个类型为 'org.flywaydb.core.Flyway' 的 bean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48950067/