Using H2 As DataSource For Testing
- In build.gradle, add
runtimeOnly 'com.h2database:h2in dependencies section - Open application.properties
- 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
- 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>