4

I have added H2DB in my springBoot application for unit testing purpose.

In application-test.properties I just added:

spring.datasource.name = h2db

spring.h2.console.enabled = true

Its working fine, saving the values.

But how it is working and how can I browse this DB?

Cepr0
  • 28,144
  • 8
  • 75
  • 101
Sharad
  • 589
  • 5
  • 19

1 Answers1

10

Default properties for H2 in Spring Boot application are:

spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect

So it's not necessary to add them to your application.properties - Spring Boot create this DB itself.


If you want to get access to your H2 DB right from your IDE you have to make this setup.

Cepr0
  • 28,144
  • 8
  • 75
  • 101
  • I have one more question on this, if I am running my local service then I can access it through its console but in case of unit testing how to use H2 console. In case of unit testing local server is not running. – Sharad Aug 29 '17 at 06:58
  • @Sharad Don't forget to accept/upvote ALL answers that helped you ))) – Cepr0 Aug 29 '17 at 06:58
  • @Sharad don't use h2-console, use your IDE (SQL IDE). But when you run test - you cannot get access to H2DB (( – Cepr0 Aug 29 '17 at 07:01