H2-Console is not showing in browser

If you have override configure method of Spring Security and you want to use console of h2 database in browser, and after connect h2-console showing loading error as shown in below image.



Then you have to add following line in your overridden configure method.

@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
  Logger logger = LoggerFactory.getLogger(SecurityConfig.class);
  
 //......
  
  
  @Override
  protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests().antMatchers("/").permitAll();
    http.authorizeRequests().antMatchers("/imgs/**").permitAll();
    http.authorizeRequests().antMatchers("/admin/**").hasRole("ADMIN");
    http.authorizeRequests().antMatchers("/**").hasRole("USER").and().formLogin();
   
    // add this line to use H2 web console

   http.headers().frameOptions().disable();

  }
}

After adding that BOLD line, your issue would be resolved. :)

Comments

Popular posts from this blog

Data Bound Controls in ASP.Net - Part 4 (FormView and DetailsView controls)

ASP.net: HttpHandlers

The Clickjacking attack and X-Frame-Options