问题
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