0

I'm using URL connection with application.yml file for my r2dbc connection. I tried to set connectTimeout property but got this error:

Caused by: java.lang.ClassCastException: class java.lang.String cannot be cast to class java.time.Duration (java.lang.String and java.time.Duration are in module java.base of loader 'bootstrap')

and I checked that r2dbc-spi configured the type of connectTimeout as java.time.Duration. And r2dbc-mysql, which I'm using follows it.

Can I use connectTimeout property with URL way? I have no idea how to automatically transfer it from string to java.time.Duration.

So far, I saw most type of connection property values are string, integer, boolean. And as I know, JDBC configured unit of connectTimeout as ms so I could easily set connectTimeout with URL. Is there any reason that r2dbc-spi choosed Duration type for it?

심시은
  • 339
  • 1
  • 5
  • 21

1 Answers1

1

I found out that from 0.8.2.RELEASE it parses DurationStr so setting connectTimeout with PnDTnHnMn.nS format works.

in MySqlConnectionFactoryProvider.java :

mapper.from(CONNECT_TIMEOUT).asInstance(Duration.class, Duration::parse)
    .into(builder::connectTimeout);

One thing is, under 0.8.2 It does not implements like this but my pom.xml was importing both 0.8.1.RELEASE and 0.8.2.RELEASE even though I did not define any 0.8.1 things. So spring used 0.8.1

r2dbc:pool:mysql://host:port/db?connectTimeout=PT3S // 3 seconds
심시은
  • 339
  • 1
  • 5
  • 21