使用Webflux时无法在localhost:8080/h2-console上访问H2 db [英] H2 db not accessible at localhost:8080/h2-console when using webflux
本文介绍了使用Webflux时无法在localhost:8080/h2-console上访问H2 db的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
H2 db.我在某处读到,只有在开发基于Servlet的应用程序时,此功能才可用.但是我在Netty中使用Webflux.那么有没有办法在这样的应用程序中查看h2控制台?
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?
推荐答案
我遇到了同样的问题,我最终在另一个端口上手动启动了控制台服务器:
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();
}
}
然后导航到http://localhost:8082(不带/h2-console).
Then navigate to http://localhost:8082 (without /h2-console).
这篇关于使用Webflux时无法在localhost:8080/h2-console上访问H2 db的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文