如何在 java ee 应用程序中启用 h2 控制台 [英] How To enable h2 console in java ee application

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

问题描述

我想在我的应用程序开发期间访问 h2 控制台功能.我使用 JavaEE 和 wildfly 作为我的应用程序服务器.

I would like to have access to h2 console feature during development of my app. I am using JavaEE and wildfly as my application server.

我知道对于 spring boot 我们需要添加以下配置行:

I know that for spring boot we need to add follwing lines of configuration:

spring.h2.console.enabled=true

spring.h2.console.path=/h2

然后我们在 http://localhost:8080/h2/

但是javaEE呢?我如何访问它?我的 pom 对 h2 有以下依赖:

But what about javaEE? How Can I access it? My pom has followin dependency to h2:

<dependency>
   <groupId>com.h2database</groupId>
   <artifactId>h2</artifactId>
   <version>1.4.196</version>
   <scope>runtime</scope>
</dependency>

和persistance.xml:

and persistance.xml:

<properties>
    <property name="eclipselink.logging.level" value="INFO"/>
    <property name="eclipselink.logging.parameters" value="true"/>

    <property name="hibernate.show_sql" value="true" />
    <property name="javax.persistence.schema-generation.database.action" value="create"/>
    <property name="javax.persistence.sql-load-script-source" value="META-INF/initial.sql"/>
</properties>

推荐答案

如果您在 JEE 服务器上部署 Spring Boot,则控制台应位于应用程序上下文路径下定义的路径中.

If you're deploying Spring Boot on the JEE server, the console should be at the defined path under the application context path.

但是,如果您要求不依赖 Spring Boot 的解决方案,则有一个 org.h2.server.web.WebServlet 正好适合这种情况.所需要做的就是使用 WEB-INF/web.xml 部署描述符公开它:

However, if you're asking for a solution that doesn't rely on Spring Boot, there is an org.h2.server.web.WebServlet that fits exactly this case. All that is needed is to expose it using the WEB-INF/web.xml deployment descriptor:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns="http://java.sun.com/xml/ns/javaee"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  version="2.5">
  <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>

这篇关于如何在 java ee 应用程序中启用 h2 控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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