10

I'm trying to leverage H2 for testing and have the following configuration in src/test/resources/application.yaml:

spring: r2dbc: url: r2dbc:h2:file://testdb 

I have an empty test annotated with @SpringBootTest but when I run it I get the following error:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.r2dbc.pool.ConnectionPool]: Factory method 'connectionFactory' threw exception; nested exception is java.lang.IllegalStateException: Unable to create a ConnectionFactory for 'ConnectionFactoryOptions{options={driver=h2, protocol=file, host=testdb}}'. Available drivers: [ pool, postgresql, h2 ] at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:651) ... 131 common frames omitted Caused by: java.lang.IllegalStateException: Unable to create a ConnectionFactory for 'ConnectionFactoryOptions{options={driver=h2, protocol=file, host=testdb}}'. Available drivers: [ pool, postgresql, h2 ] at io.r2dbc.spi.ConnectionFactories.get(ConnectionFactories.java:145) at org.springframework.boot.autoconfigure.r2dbc.ConnectionFactoryBuilder.build(ConnectionFactoryBuilder.java:125) at org.springframework.boot.autoconfigure.r2dbc.ConnectionFactoryConfigurations.createConnectionFactory(ConnectionFactoryConfigurations.java:56) at org.springframework.boot.autoconfigure.r2dbc.ConnectionFactoryConfigurations$Pool.connectionFactory(ConnectionFactoryConfigurations.java:68) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ... 132 common frames omitted 

Here are the relevant dependencies from pom.xml:

<dependency> <groupId>io.r2dbc</groupId> <artifactId>r2dbc-h2</artifactId> <version>0.8.4.RELEASE</version> <scope>test</scope> </dependency> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <version>1.4.200</version> <scope>test</scope> </dependency> 
1
  • Hi @Jit B, Could you solve the problem? I have the same one. Thanks! Commented Jun 18, 2021 at 18:20

2 Answers 2

3

Make this change to your application.yml file:

spring: r2dbc: url: r2dbc:h2:mem:///testdb #create DB in memory --- spring: r2dbc: url: r2dbc:h2:file:///./testdb #create DB in a file testdb.mv.db 
Sign up to request clarification or add additional context in comments.

Comments

3

url: r2dbc:h2:file:///./data/h2db/testdb

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.