如何在Quarkus应用程序中设置H2数据库控制台URL [英] How to set H2 Database console url in the Quarkus Application

查看:192
本文介绍了如何在Quarkus应用程序中设置H2数据库控制台URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于Spring引导应用程序提供了用于设置H2数据库的Web控制台URL的属性.

As Spring boot application provides a property to set the web console URL of the H2 Database.

spring.h2.console.path=/h2

是否可以在Quarkus应用程序中设置相同的属性?如果不是,那么默认值是什么 Web控制台URL.

Is there a way to set this same property in the Quarkus application? If not then what is the default web console URL.

推荐答案

是的,有一种方法.但这并不像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.

这篇关于如何在Quarkus应用程序中设置H2数据库控制台URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆