且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Quarkus应用程序中设置H2数据库控制台URL

更新时间:2023-01-18 17:42:18

是的,有一种方法.但这并不像Spring Boot中那么简单,因为Quarkus对Spring H2的一流支持不如Spring Boot.

Yes, there is a way. But it's not quite as simple as in Spring Boot because Quarkus does not do the same first-class support for H2 as Spring Boot does.

首先,您需要激活Quarkus中的Servlet支持.然后,继续进行操作,并在web.xml部署描述符中或如果您熟悉的话在undertow-handlers.conf中配置H2 servlet.

First, you need to activate Servlet support in Quarkus. Then, you go ahead and configure the H2 servlet in a web.xml deployment descriptor or in a undertow-handlers.conf if you're familiar with it.

我们在这里:

  1. 假设您已经添加了quarkus-jdbc-h2扩展名
  2. 添加quarkus-vertxquarkus-undertow扩展名
  3. src/main/resources/META-INF/web.xml
  4. 下创建部署描述符
  5. 像这样配置H2控制台Servlet
  1. Assuming that you already have the quarkus-jdbc-h2 extension added
  2. Add the quarkus-vertx and quarkus-undertow extensions
  3. Create the deployment descriptor under src/main/resources/META-INF/web.xml
  4. Configure the H2 console Servlet like so

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
        PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
        "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
    <display-name>My Web Application</display-name>

    <servlet>
        <servlet-name>h2-console</servlet-name>
        <servlet-class>org.h2.server.web.WebServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>h2-console</servlet-name>
        <url-pattern>/h2/*</url-pattern>
    </servlet-mapping>

</web-app>

运行./mvnw quarkus:dev并转到显示控制台的http://localhost:8080/h2.

Run ./mvnw quarkus:dev and go to http://localhost:8080/h2 where the console should show up.