Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the H2 console in Spring Boot show a blank screen after logging in?

I'm using Spring Boot 1.4.1 with the H2 database. I have enabled the H2 console as described in the reference guide by adding the following lines to my application.properties file:

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

When I go to the H2 console in Chrome 53 for Windows, I can see the login page and clicking the "Test Connection" button results in "Test successful":

enter image description here

But when I click on the "Connect" button, the screen turns completely blank. When I view the source, I see "Sorry, Lynx not supported yet" (see the full source). The same thing happens in Firefox.

Why is that happening? I believe I am using the correct JDBC URL, as 4 different people posted on this question that you should use jdbc:h2:mem:testdb.

like image 453
pacoverflow Avatar asked Oct 20 '16 23:10

pacoverflow


People also ask

How to enable H2 console in Spring Boot?

Spring Boot can auto-configure H2 database browser-based console for us. To enable the console we need to set property spring.h2.console.enabled to true (default is false, Spring Boot version 2.0.2). By default the console can be accessed at URI /h2-console which can be changed by spring.h2.console.path property.

Why can’t I access the H2 Database Console under Spring Security?

If you’ve enabled Spring Security in your Spring Boot application, you will not be able to access the H2 database console. With its default settings under Spring Boot, Spring Security will block access to H2 database console. To enable access to the H2 database console under Spring Security you need to change three things:

What is the default logging service for Spring Boot?

Default console logging Spring boot internally uses apache’s common logging and uses logback as default logging provider. If we do not make any logging specific configuration, still we see lots of logging output to console which is good enough for POC (proof of concept) purposes.

Where does H2 database store data in Spring Boot?

It stores data in memory, not persist the data on disk. Here we will be discussing how can we configure and perform some basic operations in Spring Boot using H2 Database. Some of the main features of the H2 Database are:


2 Answers

According to a blog post, a line needs to be added to the configure method of the SecurityConfig class if you have the spring-boot-starter-security dependency in your project, otherwise you will see an empty page after logging into the H2 console:

http.headers().frameOptions().disable();

I added that line and it solved the problem.

Alternatively, the following line can be used (as mentioned here):

http.headers().frameOptions().sameOrigin();
like image 135
pacoverflow Avatar answered Oct 20 '22 13:10

pacoverflow


I can resolve the same problem using the following code in my SecurityConfig class

@Override
protected void configure(HttpSecurity http) throws Exception {
    bla();
    bla();   
    http.headers().frameOptions().sameOrigin();
}

I don't know what this line does, maybe someone with more experience can explain it.

like image 22
Martin Larizzate Avatar answered Oct 20 '22 13:10

Martin Larizzate