Using H2 As DataSource For Testing

  1. In build.gradle, add runtimeOnly 'com.h2database:h2 in dependencies section
  2. Open application.properties
  3. Add lines
    spring.datasource.url=jdbc:h2:mem:testdb
    spring.datasource.driverClassName=org.h2.Driver
    spring.datasource.username=sa
    spring.datasource.password=
    spring.h2.console.enabled=true

    Note that we set console.enable to true so that we can access H2 by web browser

  4. To access the H2 database, go to http://localhost:8080/h2-console/ for default setting

For maven:

<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    <scope>runtime</scope>
</dependency>