H2-控制台未在浏览器中显示 [英] H2-Console is not showing in browser
问题描述
我正在使用SpringBoot api,并使用具有以下属性设置的H2数据库.
I am working on SpringBoot api and using H2 database with following property settings.
spring.h2.console.enabled=true
spring.datasource.name=test
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driver-class-name=org.h2.Driver
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.datasource.initialization-mode = embedded
spring.datasource.url=jdbc:h2:mem:test
spring.jpa.hibernate.ddl-auto = update
当我想使用浏览器通过' http://localhost:8082/h2-查看H2数据库控制台时控制台",在浏览器中打开一个带有连接并测试连接"按钮的屏幕.当我单击测试连接"时,它返回成功,但是当单击连接"按钮时,出现错误,表明本地主机拒绝连接.
When I want to use browser to view the H2 database console through 'http://localhost:8082/h2-console', a screen open in browser with connect and test connection button. When I click on Test Connection, it returns successful but when click on Connect button, error comes that localhost refused to connect.
推荐答案
As per this 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();
这篇关于H2-控制台未在浏览器中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!