Reputation: 11
I upgraded my application from Spring Boot 2.7.8 to 3.0.5 and I am facing problems with binding parameters in DatabaseClient
.
It is a spring gateway application which uses ReactiveSessionRepository
.
Here is the code:
My pom:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.5</version>
<relativePath/>
</parent>
.....
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
<version>${spring-cloud.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
<version>${spring-cloud.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-circuitbreaker-reactor-resilience4j</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-r2dbc</artifactId>
<version>3.0.5</version>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-core</artifactId>
</dependency>
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-postgresql</artifactId>
<version>0.8.13.RELEASE</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-pool</artifactId>
<version>1.0.0.RELEASE</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
....
Here is my Repository class:
@Repository
public class MyRepository implements ReactiveSessionRepository<Session> {
private final R2dbcEntityTemplate r2dbcEntityTemplate;
public MyRepository(final R2dbcEntityTemplate r2dbcEntityTemplate) {
this.r2dbcEntityTemplate = r2dbcEntityTemplate;
}
@Override
public Mono<Session> findById(final String s) {
return Mono.defer(() -> parse(s)
.map(a -> r2dbcEntityTemplate.getDatabaseClient()
.sql("select function_name(:a)")
.bind("a", a)
.fetch().one()
.map(map -> extract(map, "function_name"))
.flatMap(Mono::justOrEmpty))
.orElseGet(Mono::empty));
}
}
Im am getting following error:
java.lang.IllegalArgumentException: Cannot encode parameter of type io.r2dbc.spi.Parameters$InParameter
Error is happening on bind()
Do you have any idea what could be a problem?
I tried to debug it, no results. There is also nothing in google relevant to the problem. Problem is happening when I try to bind parameter, without it works normally.
Upvotes: 1
Views: 3719
Reputation: 1
I solved this problem by changing r2dbc-postgresql dependency from:
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-postgresql</artifactId>
<version>0.8.13.RELEASE</version>
<scope>runtime</scope>
</dependency>
To:
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>r2dbc-postgresql</artifactId>
</dependency>
Note they are referring to a different groupId in Maven.
Upvotes: 0
Reputation: 131
Had the same problem and conflicted versions of io.r2dbc:r2dbc-postgresql
were the issue. I removed 0.8.13.RELEASE
and now only 1.0.1.RELEASE
is included and works fine.
Upvotes: 0
Reputation: 1
I have the same problem.
The bind operator creates this problem. Version 0.8.13.RELEASE is the latest version of R2DBC on PostgreSQL. To check, I remove the bind and replace it with the String.format(SQL,value1,...) and the query is done.
So it's a problem between Spring-data-r2dbc (3.1.0) and the R2DBC driver (i suppose). With Spring-boot 2.7.X, Spring-data-r2dbc is in 1.5.6 version.
I'll keep searching!
Upvotes: 0
Reputation: 124516
Your dependencies are (part of) the problem, you are trying to manage too much. Next to that you are using an outdated and not maintained version of the PostgreSQL R2DBC driver.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>2022.0.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-circuitbreaker-reactor-resilience4j</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-r2dbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-core</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>r2dbc-postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-pool</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
Something like this should fix your dependencies.
NOTE: Also added dependencyManagement
for Spring Cloud as that is the recommended way of doing this.
Upvotes: 0