H2 Console
The H2ManagerMenu
provides a single menu item to redirect to the H2 web console.
This is only enabled for prototyping, and only if H2 is detected in the underlying JDBC URL.
The menu appears under the "Prototyping" menu.
Maven Configuration
Dependency Management
If your application inherits from the Apache Causeway starter app (org.apache.causeway.app:causeway-app-starter-parent
) then that will define the version automatically:
<parent>
<groupId>org.apache.causeway.app</groupId>
<artifactId>causeway-app-starter-parent</artifactId>
<version>2.0.0-RC1</version>
<relativePath/>
</parent>
Alternatively, import the core BOM. This is usually done in the top-level parent pom of your application:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.causeway.core</groupId>
<artifactId>causeway-core</artifactId>
<version>2.0.0-RC1</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
In addition, add a section for the BOM of all the testing support libraries:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.isis.testing</groupId>
<artifactId>isis-testing</artifactId>
<scope>import</scope>
<type>pom</type>
<version>{page-isisrel}</version>
</dependency>
</dependencies>
</dependencyManagement>
API & Implementation
The API of the service is:
public class H2ManagerMenu {
public void openH2Console() { /* ... */ }
}
Note that this launches the manager on the same host that the webapp runs, and so is only appropriate to use when running on localhost
.
Additional Configuration
The following additional configuration is also required (all of this is present in the helloworld and simpleapp starter apps):
-
the h2 jdbc driver is required on the classpath of the webapp:
pom.xml<dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> </dependency>
-
the
jdbc:h2
URL configuration properties must be defined, eg inapplication.properties
:application.propertiesspring.sql.init.platform=h2 spring.datasource.url=jdbc:h2:mem
-
finally, and most importantly, the h2 console servlet must be configured in
web.xml
, and must be mapped to/db
:web.xml<servlet> <servlet-name>H2Console</servlet-name> <servlet-class>org.h2.server.web.WebServlet</servlet-class> <init-param> <param-name>webAllowOthers</param-name> <param-value>true</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>H2Console</servlet-name> <url-pattern>/db/*</url-pattern> </servlet-mapping>
Disabling/hiding the menu
The menu can be hidden or disabled by subscribing to its domain event, eg:
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Service;
@Service
public class HideH2ManagerMenu {
@EventListener(H2ManagerMenu.ActionDomainEvent.class)
public void on(H2ManagerMenu.ActionDomainEvent ev) {
ev.hide();
}
}