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>3.1.0</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>3.1.0</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
In addition, add an entry for the BOM of all the testing support libraries:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.causeway.testing</groupId>
<artifactId>causeway-testing</artifactId>
<scope>import</scope>
<type>pom</type>
<version>2.1.0</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 (eg as 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
-
because this is a potential security risk, a further configuration property must also be explicitly enabled:
application.propertiescauseway.prototyping.h2-console.web-allow-remote-access=true
-
and if so, then the password should be randomly generated (it will be printed to the log); this is enabled by default:
application.propertiescauseway.prototyping.h2-console.generate-random-web-admin-password=true
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();
}
}
Using with Secman
If SecMan is in use, then you will also need to grant the appropriate role (CausewayExtH2ConsoleRoleAndPermissions) to the user.