在基于WebFluxNetty的应用框架中,惯常通过http://ip:port/h2-console访问的H2控制台无法打开。这个时候,可以通过显式的去启动H2 Server来解决此问题。参考代码如下:

@Component
@Profile("test") // <-- up to you
public class H2 {

private org.h2.tools.Server webServer;

private org.h2.tools.Server server;

@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.server = org.h2.tools.Server.createTcpServer("-tcpPort", "9092", "-tcpAllowOthers").start();
}

@EventListener(org.springframework.context.event.ContextClosedEvent.class)
public void stop() {
this.webServer.stop();
this.server.stop();
}

}

参考文献:Here