Spring boot 无数据源的Flyway配置
尝试使用Spring boot 无数据源的Flyway配置,spring-boot,flyway,Spring Boot,Flyway,尝试使用Spring Boot v2.2.1安装Flyway v6.0.8。在application.yaml文件中释放: spring: # CockroachDB connection r2dbc: url: r2dbc:postgresql://localhost:26257/defaultdb username: test_user password: qwerty schema: some_schema flyway: # Doe
Spring Boot v2.2.1安装Flyway v6.0.8
。在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
。据我所知,这是可能的,但我仍然面临以下关于未定义数据源的例外情况:
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")
}
}
您是否有自己的代码正在启用datasourceproperty
?如果EmbeddedDatabaseType
不在类路径上,则它应该已退出。再次检查,未配置任何可能引用DataSourceProperty的内容。更新了问题说明,在异常日志中添加了一条消息。如果查看此合并,您将看到您需要数据源。他们只是改变了数据源从何处获取的逻辑。@ViktorV。你能创建一个简单完整的例子并在某处分享吗?