Vishnu Dahatonde
Vishnu Dahatonde

Reputation: 179

H2 console does not show up

I've read almost all the questions with H2 console but did not find a solution. I am getting Whitelabel Error Page when I hit the URL http://localhost:8080/h2-console.

I have added below dependencies in my project:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>runtime</scope>>
    </dependency>
</dependencies>

application.properties

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

Whitelabel Error Page

Upvotes: 2

Views: 1778

Answers (1)

Romil Patel
Romil Patel

Reputation: 13727

Add this in application-properties

spring.h2.console.path=/h2-console

properties for H2

spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.h2.console.path=/h2-console

DB_CLOSE_DELAY = -1 is prevents the connection lost


UPDATE

For Spring Boot 2.x straight from Spring Initialzr:

Default with devtools is http://127.0.0.1:8080/h2-console/

POM: spring-boot-starter, h2, spring-boot-starter-web, spring-boot-devtools

Without devtools - you need to set it in properties:

spring.h2.console.enabled=true spring.h2.console.path=/h2-console

POM: spring-boot-starter, h2, spring-boot-starter-web

Upvotes: 5

Related Questions