H2数据库控制台spring boot X-Frame-Options拒绝加载

Pio*_*ski 15 h2 spring-boot spring-4

我正在为dev开发一个带有spring 4启动安全性的骨架项目.尝试登录数据库控制台并管理我的数据库时使用H2我收到以下错误.该页面是空白的,在firebug konsole中有4个错误:

 Load denied by X-Frame-Options: http://localhost:8080/console
Run Code Online (Sandbox Code Playgroud)

有链接

/header.jsp?jsessionid=f71207a702c9177e57208414721bbe93 does not permit framing.
/query.jsp?jsessionid=f71207a702c9177e57208414721bbe93 does not permit framing.
/help.jsp?jsessionid=f71207a702c9177e57208414721bbe93 does not permit framing.
/tables.do?jsessionid=f71207a702c9177e57208414721bbe93 does not permit framing.
Run Code Online (Sandbox Code Playgroud)
  1. 我可以从控制台级别测试连接 - 确定.
  2. DB工作正常,import.sql工作正常,我可以用spring创建用户实体启动.

我正在使用的配置来自(并且它适用于带有xml配置的spring 3.2)

spring boot默认H2 jdbc连接(和H2控制台)

使用:spring-boot-starter-parent 1.1.4.RELEASE

pVi*_*aca 37

也可以通过以下方式简化@chrosciu的答案:

@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

  @Override
  protected void configure(HttpSecurity http) throws Exception {
    http.headers().frameOptions().disable();
  }
}
Run Code Online (Sandbox Code Playgroud)

  • 或者,更安全地,`headers().frameOptions().sameOrigin()`. (11认同)

Pio*_*ski 5

将下面的代码添加到 Application.java 中,现在它可以工作,默认端口为 8082,从 spring 应用程序开始。它没有达到目的,但出于开发目的,一切正常。

@Bean
org.h2.tools.Server h2Server() {
    Server server = new Server();
    try {
        server.runTool("-tcp");
        server.runTool("-tcpAllowOthers");
    } catch (Exception e) {
        e.printStackTrace();
    }
    return server;

}
Run Code Online (Sandbox Code Playgroud)