當你嘗試在Spring Boot項目中使用iframe標簽時,瀏覽器會報“in a frame because it set 'X-Frame-Options' to 'deny'.”的錯誤。解決辦法如下:
@EnableWebSecurity
public class WebSecurityConfig extends
WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
// ...
.headers()
.frameOptions().sameOrigin()
.httpStrictTransportSecurity().disable();
}
}
參考https://docs.spring.io/spring-security/site/docs/current/reference/html/headers.html