带有Flyway 4.2.0的Spring Boot 2.1.0 [英] Spring Boot 2.1.0 with Flyway 4.2.0

查看:159
本文介绍了带有Flyway 4.2.0的Spring Boot 2.1.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将新项目升级到Spring Boot版本2.1.0,但是我受限于 Flyway 4.2.0 库支持的Oracle 11数据库.一切都可以在Spring Boot 2.0.5版本上正常运行,但是当移至 2.1.0 版本时,我会收到此错误:

I would like to upgrade for my new projects to Spring Boot version 2.1.0, but I am limited with Oracle 11 database, which is supported by the Flyway 4.2.0 library. Everything runs normally on Spring Boot version 2.0.5 Release, but when moving to 2.1.0 release I get this error:

java.lang.NoClassDefFoundError: 
org/flywaydb/core/api/configuration/FluentConfiguration

POM配置如下:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.0.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <ojdbc6.version>11.2.0.1</ojdbc6.version>
</properties>

<dependencies>
    <dependency>
        <groupId>com.oracle.jdbc</groupId>
        <artifactId>ojdbc6</artifactId>
        <version>${ojdbc6.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.flywaydb</groupId>
        <artifactId>flyway-core</artifactId>
        <version>4.2.0</version>
    </dependency>
</dependencies>

更新

我可以通过@Configuration解决问题(或者当然可以添加到主类中),但问题是它的错误或功能?在2.1.0版之前,所有操作都是通过自动配置完成的,并且可以直接使用.

UPDATE

I am able to solve the problem via @Configuration (or of course add to the main class), but the thing is its a bug or feature? Prior to version 2.1.0 everything was done via autoconfiguration and it works out-of-box.

@Bean(initMethod = "migrate")
Flyway flyway() {
    Flyway flyway = new Flyway();
    flyway.setBaselineOnMigrate(true);
    flyway.setDataSource("jdbc:oracle:thin:@localhost:1521:xe", "USER", "PASSWORD1");
    return flyway;
}

推荐答案

我在PostgreSQL 9.2中遇到了相同的问题,并使用以下类解决了该问题.

I had the same problem with PostgreSQL 9.2, and used the following class to solve the problem.

请注意,尽管您可能会在Spring Boot属性中设置的所有自定义属性都将被忽略,因为这会自己替换整个Flyway自动配置.因此,您可能必须添加一些其他代码以满足您的需求.

Be aware though that all the custom properties you might set in the Spring Boot properties will be ignored, since that replaces the whole Flyway autoconfiguration by your own. So you might have to add some additional code to fit your needs.

@Configuration
class FlywayConfig {
    @Bean
    fun flyway(dataSource: DataSource): Flyway {
        val flyway = Flyway()
        flyway.dataSource = dataSource
        return flyway
    }

    @Bean
    fun flywayInitializer(flyway: Flyway): FlywayMigrationInitializer {
        return FlywayMigrationInitializer(flyway, null)
    }

    /**
     * Additional configuration to ensure that [EntityManagerFactory] beans depend on the
     * `flywayInitializer` bean.
     */
    @Configuration
    class FlywayInitializerJpaDependencyConfiguration : EntityManagerFactoryDependsOnPostProcessor("flywayInitializer")
}

PS:这是Kotlin代码,但是您应该能够轻松地将其转换为Java.

PS: this is Kotlin code, but you should be able to translate it to Java fairly easily.

这篇关于带有Flyway 4.2.0的Spring Boot 2.1.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆