热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

H2数据库控制台spring启动负载被x帧选项拒绝。-H2databaseconsolespringbootLoaddeniedbyX-Frame-Options

I`mbuildingaskeletalprojectfordevwithspring4bootsecurityandothers.UsingH2whileattem

I`m building a skeletal project for dev with spring 4 boot security and others. Using H2 while attempting to log into the db console and manage my db i get the following error. The page is blank, with 4 bugs in firebug konsole :

我正在为dev构建一个包含spring 4引导安全性和其他特性的框架项目。使用H2登录到db控制台并管理我的db时,我得到以下错误。页面为空白,firebug konsole中有4个bug:

 Load denied by X-Frame-Options: http://localhost:8080/console

With links to

/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.
  1. I can test the connection from console level - its ok.
  2. 我可以从控制台级别测试连接——没问题。
  3. DB works fine, import.sql works fine, i can create user entities withing spring is starting up.
  4. DB没问题,导入。sql运行良好,我可以在spring启动时创建用户实体。

The configuration i am using is from (and it works on spring 3.2 with xml configuration)

我使用的配置来自(它在spring 3.2中使用xml配置)

spring boot default H2 jdbc connection (and H2 console)

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

Using : spring-boot-starter-parent 1.1.4.RELEASE

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

3 个解决方案

#1


10  

It's also possible to simplify the answer from @chrosciu with this:

也可以用以下方法简化@chrosciu的答案:

@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

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

#2


4  

Added the code below to Application.java and for now it works, default on port 8082, starts with spring app. It doesn`t hit the spot but for dev purposes it is all ok.

将下面的代码添加到应用程序中。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;

}

#3


2  

This worked for me:

这工作对我来说:

@EnableWebSecurity
@Configuration
class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.headers().addHeaderWriter(
            new XFrameOptionsHeaderWriter(
                new WhiteListedAllowFromStrategy(Arrays.asList("localhost"))));
    }
}

Of course contents of white list should be adjusted in case when application is running on something different than localhost.

当然,当应用程序运行在与localhost不同的东西上时,应该调整白列表的内容。


推荐阅读
author-avatar
ccmmm
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有