如何在Spring Boot应用程序中解决FlyWay许可证问题

X-H*_*Man 4 java license-key flyway spring-boot

使用FlyWay企业许可证的我的Spring Boot应用程序无法启动,并显示以下消息:

Caused by: org.flywaydb.core.api.FlywayException: Missing license key. 
Ensure flyway.licenseKey is set to a valid Flyway license key ("FL01" followed by 512 hex chars)
Run Code Online (Sandbox Code Playgroud)

许可证实际上并没有丢失。我试图将既设置为env变量,又设置为application.yml文件,名称为spring >> flyway >> licenseKey,但它根本没有反应。

有什么想法可以隐藏问题吗?Spring引导会考虑使用其他env变量作为数据库,因此这不是问题。

Tod*_*odd 5

在GitHub上对此进行了很好的讨论。根据该问题,Spring Boot 2.2的路线图似乎是基于属性的版本。

显然,现在您需要实现FlywayConfigurationCustomizer(未经测试):

@Configuration
public class FlywayConfiguration {
    @Bean
    public FlywayConfigurationCustomizer customizeLicense(
                 @Value("${my-app.flyway.license}") String license) {
        return new FlywayConfigurationCustomizer() {

            @Override
            public void customize(FluentConfiguration configuration) {
                configuration.licenseKey(license);
            }
        };
    }
}
Run Code Online (Sandbox Code Playgroud)

我认为可以将其简化为lambda(也未经测试)...

@Configuration
public class FlywayConfiguration {
    @Bean
    public FlywayConfigurationCustomizer customizeLicense(
                 @Value("${my-app.flyway.license}") String license) {
        return configuration -> configuration.licenseKey(license);
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 就像魅力一样,非常感谢您的回答。令人惊讶的是,专业人士的句子很少能节省大量时间和金钱,有时又可以节省其他人的工作:) (2认同)