Boot中的H2控制台登录后显示空白屏幕

Boot中的H2控制台登录后显示空白屏幕

本文介绍了为什么在Spring Boot中的H2控制台登录后显示空白屏幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Spring Boot 1.4.1与H2数据库一起使用.我已经按照参考指南,方法是将以下几行添加到我的application.properties文件中:

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

当我进入Windows的Chrome 53中的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":

但是,当我单击连接"按钮时,屏幕完全变为空白.当我查看源代码时,看到很抱歉,尚不支持Lynx"(请参阅​​完整源代码). Firefox中也会发生同样的事情.

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.

为什么会这样?我相信我使用的是正确的JDBC URL,因为有4个不同的人发布在,您应该使用jdbc:h2:mem:testdb.

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.

推荐答案

根据博客文章,需要在其中添加一行SecurityConfig类的configure方法(如果您的项目中具有spring-boot-starter-security依赖项),否则登录到H2控制台后将看到一个空白页面:

According to a blog post, a line needs to be added tothe 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();

这篇关于为什么在Spring Boot中的H2控制台登录后显示空白屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 07:50