Problem: starter-data-r2dbc library throws exception when booting up a spring boot webflux project that also includes vavr

Java SDK: Eclipse Temurin version 20.0.2

Exception:

2023-09-27T13:54:49.798-0500 [QUIET] [system.out] 2023-09-27T13:54:49.799-05:00  WARN 5271 --- [           main] onfigReactiveWebServerApplicationContex
t : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error cre
ating bean with name 'r2dbcEntityTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/r2dbc/R2dbcDataAutoConfiguration.
class]: Failed to instantiate [org.springframework.data.r2dbc.core.R2dbcEntityTemplate]: Factory method 'r2dbcEntityTemplate' threw exception with messa
ge: Method 'io.vavr.control.Option io.vavr.control.Option.none()' must be Methodref constant

Files: This problem can be recreated with a minimal project build off of the spring initializer, with some minor tweaks for the following files.

build.gradle


plugins {
    id 'java'
    id 'org.springframework.boot' version '3.1.3'
    id 'io.spring.dependency-management' version '1.1.3'
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-r2dbc' // <-- commenting this line "resolves" the issue
    implementation 'org.springframework.boot:spring-boot-starter-webflux'
    runtimeOnly('io.r2dbc:r2dbc-h2:1.0.0.RELEASE')
    implementation 'io.vavr:vavr:1.0.0-alpha-4'
}

application.yml

spring:
  r2dbc:
    url: r2dbc:h2:mem:///testdb #create DB in memory

Comment From: scottfrederick

While Spring Boot is in the stacktrace for this error, the code that is attempting to deal with the io.vavr.control.Option class is in Spring Data:

Caused by: java.lang.IncompatibleClassChangeError: Method 'io.vavr.control.Option io.vavr.control.Option.none()' must be Methodref constant
    at org.springframework.data.util.NullableWrapperConverters$NullableWrapperToVavrOptionConverter.<init>(NullableWrapperConverters.java:357) ~[spring-data-commons-3.1.4.jar:3.1.4]
    at org.springframework.data.util.NullableWrapperConverters$NullableWrapperToVavrOptionConverter.<clinit>(NullableWrapperConverters.java:354) ~[spring-data-commons-3.1.4.jar:3.1.4]
    at org.springframework.data.util.NullableWrapperConverters.<clinit>(NullableWrapperConverters.java:91) ~[spring-data-commons-3.1.4.jar:3.1.4]
    at org.springframework.data.projection.ProxyProjectionFactory.<clinit>(ProxyProjectionFactory.java:58) ~[spring-data-commons-3.1.4.jar:3.1.4]
    at org.springframework.data.r2dbc.core.R2dbcEntityTemplate.<init>(R2dbcEntityTemplate.java:161) ~[spring-data-r2dbc-3.1.4.jar:3.1.4]
    at org.springframework.data.r2dbc.core.R2dbcEntityTemplate.<init>(R2dbcEntityTemplate.java:144) ~[spring-data-r2dbc-3.1.4.jar:3.1.4]
    at org.springframework.boot.autoconfigure.data.r2dbc.R2dbcDataAutoConfiguration.r2dbcEntityTemplate(R2dbcDataAutoConfiguration.java:71) ~[spring-boot-autoconfigure-3.1.4.jar:3.1.4]

Please either re-open https://github.com/spring-projects/spring-data-commons/issues/2946 or open a new issue in Spring Data Commons so the Spring Data team can take a look.

Comment From: AlbertSnows

ahhh, I closed the one I made there for this. My bad.