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

后端 未结 1 442
时光说笑
时光说笑 2020-12-17 21:48

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 u

相关标签:
1条回答
  • 2020-12-17 22:40

    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).

    0 讨论(0)
提交回复
热议问题