Skip to content

Instantly share code, notes, and snippets.

@gclaussn
Last active November 7, 2018 21:00
Show Gist options
  • Save gclaussn/4e6f195f3c06b9d46f263d340155ac9d to your computer and use it in GitHub Desktop.
Save gclaussn/4e6f195f3c06b9d46f263d340155ac9d to your computer and use it in GitHub Desktop.
Spring Boot - Enable H2 web console

Add H2 to Maven dependencies

<dependency>
  <groupId>com.h2database</groupId>
  <artifactId>h2</artifactId>
  <scope>runtime</scope>
</dependency>

Add properties to the application context

spring.h2.console.enabled=true
spring.h2.console.path=/h2

db.driver.class.name=org.h2.Driver
db.url=jdbc:h2:mem:test;DB_CLOSE_DELAY=-1
db.username=
db.password=

Disable frame options in web security configuration

@Configuration
@EnableWebSecurity
@Profile("local")
public class WebSecurityConfigurationLocal extends WebSecurityConfigurerAdapter {

  @Override
  protected void configure(HttpSecurity http) throws Exception {
    // Permissions
    // ...
    
    // For H2 web console
    http.headers().frameOptions().disable();
  }
}

Open /h2 and login with:

  • JDBC URL: jdbc:h2:mem:test;DB_CLOSE_DELAY=-1
  • Username:
  • Password:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment