没有数据源的Flyway配置

时间:2019-12-16 22:16:59

标签: spring-boot flyway

尝试在Flyway v6.0.8文件中用Spring Boot v2.2.1.RELEASE设置application.yaml

spring:

  # CockroachDB connection
  r2dbc:
    url: r2dbc:postgresql://localhost:26257/defaultdb
    username: test_user
    password: qwerty
    schema: some_schema

  flyway:
    # Doesn't support r2dbc driver, and don't think it's really necessary just for database structuring(will be no actual data migrations) 
    url: jdbc:postgresql://localhost:26257/defaultdb 
    # schemas: some_schema
    user: test_user
    password: qwerty

我想仅使用spring.flyway.url/user/password来配置Flyway,而无需另外定义任何spring.datasource。据我了解,可以基于this merged PR进行操作,但是对于未定义的数据源,我仍然面临以下例外情况:

Caused by: Error creating bean with name 'flyway' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Unsatisfied dependency expressed through method 'flyway' parameter 1; nested exception org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'spring.datasource-org.springframework.boot.autoconfigure.jdbc.DataSourceProperties': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.autoconfigure.jdbc.DataSourceProperties]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseType

我做错了什么?

build.gradle

plugins {
    id 'org.flywaydb.flyway' version '6.1.1'
    id 'org.springframework.boot' version '2.2.1.RELEASE'
}

apply plugin: 'io.spring.dependency-management'

repositories {
    mavenCentral()
    maven { url = uri("https://repo.spring.io/milestone") }
}

ext {
    r2dbcPostgresqlVersion = '0.8.0.RELEASE'
    postgresqlVersion = '42.2.9'
}

dependencies {
    implementation("org.springframework.boot.experimental:spring-boot-starter-data-r2dbc")
    implementation('org.springframework.boot:spring-boot-starter-webflux')
    implementation('org.flywaydb:flyway-core')

    implementation("io.r2dbc:r2dbc-postgresql:${r2dbcPostgresqlVersion}")
    implementation("org.postgresql:postgresql:${postgresqlVersion}")

    compileOnly('org.projectlombok:lombok')

    annotationProcessor('org.projectlombok:lombok')
    annotationProcessor('org.springframework.boot:spring-boot-configuration-processor')

    testImplementation('org.springframework.boot:spring-boot-starter-test')
    testImplementation('io.projectreactor:reactor-test')
}

dependencyManagement {
    imports {
        mavenBom("org.springframework.boot.experimental:spring-boot-bom-r2dbc:0.1.0.M3")
    }
}

0 个答案:

没有答案