我正在使用spring 4启动安全性和其他人为dev构建一个骨架项目。 尝试登录数据库控制台并管理我的数据库时使用H2我收到以下错误。该页面是空白的,在firebug konsole中有4个错误:
Load denied by X-Frame-Options: http://localhost:8080/console
带有
的链接/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.
我正在使用的配置来自(并且它适用于带有xml配置的spring 3.2)
spring boot default H2 jdbc connection (and H2 console)
使用: 弹簧引导启动父 1.1.4.RELEASE
答案 0 :(得分:30)
也可以通过以下方式简化@chrosciu的答案:
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.headers().frameOptions().disable();
}
}
答案 1 :(得分:4)
将以下代码添加到Application.java中,现在它可以工作,默认在端口8082上,以spring app开头。它并没有达到目的,但出于开发目的,一切都还好。
@Bean
org.h2.tools.Server h2Server() {
Server server = new Server();
try {
server.runTool("-tcp");
server.runTool("-tcpAllowOthers");
} catch (Exception e) {
e.printStackTrace();
}
return server;
}
答案 2 :(得分:2)
这对我有用:
@EnableWebSecurity
@Configuration
class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.headers().addHeaderWriter(
new XFrameOptionsHeaderWriter(
new WhiteListedAllowFromStrategy(Arrays.asList("localhost"))));
}
}
当然,如果应用程序在不同于localhost的情况下运行,则应调整白名单的内容。