H2 db is not accessible at localhost:8080/h2-console
when using webflux
. I read somewhere that this is available only when developing a Servlet-based application. But I am using Webflux with Netty. So is there a way to see the h2 console in such an application?
Asked
Active
Viewed 7,232 times
20

Saikat
- 14,222
- 20
- 104
- 125

Krishnakumar R
- 362
- 2
- 18
2 Answers
26
I had the same issue, I ended up booting the console server manually on another port:
@Component
@Profile("test") // <-- up to you
public class H2 {
private org.h2.tools.Server webServer;
private org.h2.tools.Server tcpServer;
@EventListener(org.springframework.context.event.ContextRefreshedEvent.class)
public void start() throws java.sql.SQLException {
this.webServer = org.h2.tools.Server.createWebServer("-webPort", "8082", "-tcpAllowOthers").start();
this.tcpServer = org.h2.tools.Server.createTcpServer("-tcpPort", "9092", "-tcpAllowOthers").start();
}
@EventListener(org.springframework.context.event.ContextClosedEvent.class)
public void stop() {
this.tcpServer.stop();
this.webServer.stop();
}
}
Then navigate to http://localhost:8082 (without /h2-console).

sp00m
- 47,968
- 31
- 142
- 252
-
2Thank you. That will suffice and is perfect for my requirement. Amazed at the way people get over things. – Krishnakumar R Oct 23 '18 at 15:15
-
2hi , used same code as above , getting error like "File not found: h2" – prasannajoshi Apr 08 '19 at 05:21
-
1same issue as @prasannajoshi, "File not found: h2-console", no exceptions or stack trace – EvilJinious1 Sep 26 '19 at 14:09
-
2Remove the url path. It's accessible on http://localhost:8082 – Rodrigo Ribeiro Nov 21 '19 at 11:05
-
You can move the start method to your application class and just start it there inside the main() function and it works. Just access localhost:8082 – NMP Feb 09 '20 at 14:21
-
@Sp00m thank you for the great solution. Do you know why this problem happens? It's interesting. – Cebrail Yilmaz Oct 10 '20 at 22:09
-
@prasannajoshi don't add 'h2/console' just "http://localhost:8082" – Smaillns Feb 03 '21 at 06:48
-
I cannot seem to get it to work, when i hit localhost:8082, i get the following error: "This site can’t be reached" – AKJ May 06 '21 at 06:02
3
I found a library that does exactly the same sp00m described, it may be helpful for somebody. It works out of the box.
https://mvnrepository.com/artifact/me.yaman.can/spring-boot-webflux-h2-console
And github page: https://github.com/canyaman/spring-boot-webflux-h2-console

DamienMiheev
- 998
- 8
- 31