Spring Boot 的 Flyway 迁移错误详细信息

Xav*_*ois 3 spring flyway spring-boot

我们有一个使用 Spring Boot 和 Flyway 的项目。

当我们运行失败的迁移且日志级别全部设置为 DEBUG 时,我们只收到以下消息:

[DEBUG] org.flywaydb.core.internal.command.DbValidate - Validating migrations ...
[DEBUG] org.flywaydb.core.internal.scanner.Scanner - Filtering out resource: db/migration/V1/V1_202103081030__account.sql (filename: V1_202103081030__account.sql)
[DEBUG] org.flywaydb.core.internal.scanner.Scanner - Filtering out resource: db/migration/V1/V1_202103081040__place.sql (filename: V1_202103081040__place.sql)
[DEBUG] org.flywaydb.core.internal.scanner.Scanner - Filtering out resource: db/migration/V1/V1_202103151608__document.sql (filename: V1_202103151608__document.sql)
[DEBUG] org.flywaydb.core.Flyway - Memory usage: 147 of 254M
[ERROR] org.springframework.boot.web.embedded.tomcat.TomcatStarter - Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'webSecurityConfig': Unsatisfied dependency expressed through method 'setContentNegotationStrategy' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration': Unsatisfied dependency expressed through method 'setConfigurers' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'openEntityManagerInViewInterceptorConfigurer' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration$JpaWebConfiguration.class]: Unsatisfied dependency expressed through method 'openEntityManagerInViewInterceptorConfigurer' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'openEntityManagerInViewInterceptor' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration$JpaWebConfiguration.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.api.exception.FlywayValidateException: Validate failed: Migrations have failed validation
...
[INFO ] org.apache.catalina.core.StandardService - Stopping service [Tomcat]
...
Caused by: org.flywaydb.core.api.exception.FlywayValidateException: Validate failed: Migrations have failed validation
Run Code Online (Sandbox Code Playgroud)

没有关于失败原因的更多详细信息(失败的查询、不匹配的校验和……)。

我查看了spring.flyway应用程序属性,但发现没有任何帮助。

我们应该怎么做才能在服务器启动时在日志中显示 Flyway root 错误?

编辑:要明确的是,问题不是失败本身(在 Flyway 类中设置断点可以揭示源错误)。问题是日志中缺少错误详细信息。

小智 6

我遇到了同样的问题,发现它与我使用的 Flyway 版本有关(Spring Boot 2.4.3,它使用 Flyway 7.1.1)。这是一个已知问题2987 - 在异常中显示所有验证消息,已在 Flyway 7.2.0中修复。

他们建议将运行flyway validate -outputType=json作为解决方法来获取详细的错误消息。我尝试了,但仍然没有收到详细的错误消息。

对我有用的解决方案是通过在我的 pom 文件中指定版本来升级到 Flyway 7.2.0:

<dependency>
    <groupId>org.flywaydb</groupId>
    <artifactId>flyway-core</artifactId>
    <version>7.2.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)