Add auto-configuration for H2’s web console

Three conditions must be met for the console to be enabled:

 - H2 is on the classpath
 - The application is a web application
 - spring.h2.console.enabled is set to true

If spring-boot-devtools is on the classpath, spring.h2.console.enabled
will be set to true automatically. Without the dev tools, the enabled
property will have to be set to true in application.properties.

By default, the console is available at /h2-console. This can be
configured via the spring.h2.console.path property. The value of this
property must begin with a '/'.

When Spring Security is on the classpath the console will be secured
based on the user's security.* configuration. When the console is
secured, CSRF protection is disabled and frame options is set to
SAMEORIGIN for its path. Both settings are required in order for the
console to function.

Closes gh-766
This commit is contained in:
Andy Wilkinson
2015-08-04 11:33:16 +01:00
parent f95c95a1f1
commit 2a5a32b603
9 changed files with 431 additions and 4 deletions

View File

@@ -162,6 +162,10 @@ content into your application; rather pick only the properties that you need.
multipart.max-file-size=1Mb # Max file size.
multipart.max-request-size=10Mb # Max request size.
# H2 Web Console ({sc-spring-boot-autoconfigure}/h2/H2ConsoleProperties.{sc-ext}[H2ConsoleProperties])
spring.h2.console.enable=false # Enable the console
spring.h2.console.path=/h2-console # Path at which the console can be accessed
# SPRING HATEOAS ({sc-spring-boot-autoconfigure}/hateoas/HateoasProperties.{sc-ext}[HateoasProperties])
spring.hateoas.apply-to-primary-object-mapper=true # if the primary mapper should also be configured

View File

@@ -2258,6 +2258,45 @@ Hibernate autoconfig is active because the `ddl-auto` settings are more fine-gra
[[boot-features-sql-h2-console]]
=== Using H2's web console
The http://www.h2database.com[H2 database] provides a
http://www.h2database.com/html/quickstart.html#h2_console[browser-based console] that
Spring Boot can auto-configure for you. The console will be auto-configured when the
following conditions are met:
* You are developing a web application
* `com.h2database:h2` is on the classpath
* You are using <<using-spring-boot.adoc#using-boot-devtools,Spring Boot's developer
tools>>
TIP: If you are not using Spring Boot's developer tools, but would still like to make use
of H2's console, then you can do so by configuring the `spring.h2.console.enabled`
property with a value of `true`. The H2 console is only intended for use during
development so care should be taken to ensure that `spring.h2.console.enabled` is not set
to `true` in production.
[[boot-features-sql-h2-console-custom-path]]
==== Changing the H2 console's path
By default the console will be available at `/h2-console`. You can customize the console's
path using the `spring.h2.console.path` property.
[[boot-features-sql-h2-console-securing]]
==== Securing the H2 console
When Spring Security is one the and basic auth is enabled, the H2 console will be
automatically secured using basic auth. The following properties can be used to customize
the security configuration:
* `security.user.role`
* `security.basic.authorize-mode`
* `security.basic.enabled`
[[boot-features-jooq]]
== Using jOOQ
Java Object Oriented Querying (http://www.jooq.org/[jOOQ]) is a popular product from