H2 db not accessible at localhost:8080/h2-console when using webflux

我是研究僧i 提交于 2019-12-22 18:25:09

问题


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?


回答1:


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 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();
    }

}


来源:https://stackoverflow.com/questions/52949088/h2-db-not-accessible-at-localhost8080-h2-console-when-using-webflux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!