如何在Quarkus应用程序中设置H2数据库控制台URL [英] How to set H2 Database console url in the Quarkus Application
问题描述
由于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.
我们在这里:
- 假设您已经添加了
quarkus-jdbc-h2
扩展名 - 添加
quarkus-vertx
和quarkus-undertow
扩展名 - 在
src/main/resources/META-INF/web.xml
下创建部署描述符
- 像这样配置H2控制台Servlet
- Assuming that you already have the
quarkus-jdbc-h2
extension added - Add the
quarkus-vertx
andquarkus-undertow
extensions - Create the deployment descriptor under
src/main/resources/META-INF/web.xml
- 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屋!