SpringBoot Accessing H2 console
Remove all you have in your properties file. All of those you mentioned are default. Spring-boot will configure it any way as soon as it identifies h2 dependency in your pom. And also you don't need that ServletRegistration
bean. Remove that as well. Just put this in your properties file
spring.h2.console.enabled=true
.
By default console can be accessed on http://localhost:8080/h2-console
, default path is h2-console
. You can configure it using spring.h2.console.path
property.
We only need below configuration in application.properties
file:
spring.h2.console.enabled=true
By default h2 will be available at http://localhost:8080/h2-console/
But one can define spring.h2.console.path=/h2
in application.properties
and after that h2 can be accessed using http://localhost:8080/h2
.
Now if you have implemented SecurityConfig
in application then you will need to add
// Make H2-Console non-secured; for debug purposes
.and().csrf().ignoringAntMatchers("/h2/**")
// Allow pages to be loaded in frames from
// the same origin; needed for H2-Console
.and().headers().frameOptions().sameOrigin()
in http.authorizeRequests()