https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#boot-features-sql-h2-console
The H2 database provides a browser-based console that Spring Boot can auto-configure for you. The console is auto-configured when the following conditions are met:
- You are developing a web application.
- com.h2database:h2 is on the classpath.
- You are using Spring Boot’s developer tools.
If you are not using Spring Boot’s developer tools but would still like to make use of H2’s console, you can configure the spring.h2.console.enabled property with a value of true.
- You are developing a web application. YES!
<artifactId>spring-boot-starter-webflux</artifactId> - com.h2database:h2 is on the classpath. YES!
<artifactId>h2</artifactId> - You are using Spring Boot’s developer tools YES!
<artifactId>spring-boot-devtools</artifactId> - I also tried adding spring.h2.console.enabled=true without success
The only success I had is manually configuring the web server.
Example:
@Component
public class H2Configuration {
private Server webServer;
private Server tcpServer;
@EventListener(org.springframework.context.event.ContextRefreshedEvent.class)
public void start() throws SQLException {
this.webServer = Server.createWebServer("-webPort", "8082", "-tcpAllowOthers").start();
this.tcpServer = Server.createTcpServer("-tcpPort", "9092", "-tcpAllowOthers").start();
}
@EventListener(org.springframework.context.event.ContextClosedEvent.class)
public void stop() {
this.webServer.stop();
this.tcpServer.stop();
}
}
This leads to me believing the documentation is incomplete and I am not alone. Someone raised this issue once but it got closed. Can this be clarified in the documentation?
https://github.com/spring-projects/spring-boot/issues/12603
Comment From: scottfrederick
@M-Smits The #12603 issue you mentioned was addressed in Spring Boot version 2.0.1, as can be seen by the milestone assigned to the issue. The documentation for version 2.0.1 has this clarification:
You are developing a servlet-based web application.
Since you are using spring-boot-starter-webflux, you are not developing a servlet-based web application.