java - 无法在本地主机 :8080/h2-console when using webflux 访问 H2 数据库

标签 java spring h2 spring-webflux

使用 webflux 时,无法在 localhost:8080/h2-console 访问 H2 数据库。我在某处读到这仅在开发基于 Servlet 的应用程序时可用。但我正在将 Webflux 与 Netty 结合使用。那么有没有办法在这样的应用程序中看到h2控制台呢?

最佳答案

我有同样的问题,我最终在另一个端口上手动启动了控制台服务器:

@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)。

关于java - 无法在本地主机 :8080/h2-console when using webflux 访问 H2 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52949088/

相关文章:

java - 类型 JList 不接受参数类型 <String>

java - RabbitMQ 请求响应和消息确认

java - H2 - 使用索引号更新每行(0,1,2,3,..)

java - 如何让jOOQ生成不引用主键的复合外键?

java - 关于Java代码风格的问题

java - 泛型函数是如何在java中实现的?

java - 仅调整指定组件大小的面板

java - 在 spring-context.xml 和 persistence.xml 中加载 .properties

java - Spring Boot @Async 方法同步执行

java - 程序在检索到包含 CLOB 的 100 行后挂起