2

Trying to run spring boot with r2dbc and init database. My build.gradle looks like:

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-r2dbc'
    implementation 'org.springframework.boot:spring-boot-starter-webflux'
    implementation 'org.liquibase:liquibase-core'

    compileOnly 'org.projectlombok:lombok'

    runtimeOnly 'org.liquibase:liquibase-core'
    runtimeOnly 'com.h2database:h2'
    runtimeOnly 'io.r2dbc:r2dbc-h2'
    runtimeOnly 'io.r2dbc:r2dbc-postgresql'
    runtimeOnly 'org.postgresql:postgresql'

    annotationProcessor 'org.projectlombok:lombok'

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

Spring properties:

spring.r2dbc.url=r2dbc:postgresql://127.0.0.1:5432/test
spring.r2dbc.username=postgres
spring.r2dbc.password=123
spring.r2dbc.pool.enabled=true
spring.r2dbc.pool.initial-size=10
spring.data.r2dbc.repositories.enabled=true

spring.liquibase.change-log=classpath:/db/changelog/db.changelog-master.yaml
spring.liquibase.url=jdbc:postgresql://127.0.0.1:5432/test
spring.liquibase.user=postgres
spring.datasource.driver-class-name=org.postgresql.Driver
logging.level.liquibase = INFO

And after starting it falls with

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [liquibase.integration.spring.SpringLiquibase]: Factory method 'liquibase' threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/jdbc/datasource/SimpleDriverDataSource

What do I do incorrectly?

tarmogoyf
  • 298
  • 3
  • 17
  • upd. if I add org.springframework.boot:spring-boot-starter-data-jpa dependency, it starts falling with NoBeanAvailable exception: can't instantiate Repository. – tarmogoyf May 28 '21 at 12:54

1 Answers1

2

You need to add a dependency on org.springframework:spring-jdbc. From the Spring Boot reference documentation:

Alternatively, you can configure either Flyway or Liquibase to configure a DataSource for you for the duration of the migration. Both these libraries offer properties to set the url, username and password of the database to migrate.

When choosing this option, org.springframework:spring-jdbc is still a required dependency.

Andy Wilkinson
  • 108,729
  • 24
  • 257
  • 242