Spring Boot/H2 Console not showing my table

Spring Boot/H2 Console not showing my table

I ran into the same problem and it took a while to find out why tables were missing. In my case I have changed the jdbc url from jdbc:h2:~/test to jdbc:h2:mem:testdb which is the default h2 database created by spring boot.

Also find comments on spring boot default H2 jdbc connection (and H2 console)

You need to register bean for showing h2 console like:

@Bean   
public ServletRegistrationBean h2servletRegistration() {        
        ServletRegistrationBean registrationBean = new ServletRegistrationBean(new WebServlet());       
        registrationBean.addUrlMappings(/console/*);      
        return registrationBean;    
}

and invoke the H2 console from browser like:

http://localhost:8080/console

Note: Port number will be port on which your spring boot application is running

Add below lines to application.properties

spring.h2.console.enabled=true
spring.datasource.platform=h2
spring.datasource.driverClassName = org.h2.Driver
spring.datasource.url=jdbc:h2:file:~/test;
spring.datasource.username=sa
spring.datasource.password=

Spring Boot/H2 Console not showing my table

Ok so that was silly. When i changed the name of my sql file to schema.sql, it worked…

Leave a Reply

Your email address will not be published. Required fields are marked *