I would like to use an H2 database in a Spring Boot application.
This is what I have in application.properties:
spring.datasource.name=testdb
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=whydoesthishavetobe
spring.datasource.password=sodifficult
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
This are the relevant lines in the build.gradle file:
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
runtimeOnly 'com.h2database:h2'
When I check the connection for the H2 database, it's all good.
But despite this, when I POST new entities into the application, I see nothing getting created in the H2 database, and Hikari data source is getting used instead in the background, as I see from the logs.
Why is Spring ignoring the application.properties file and not using the H2 data source? How can I force it to use the H2 data source?
This is Spring Boot 2.3.4.RELEASE.