I'm looking for a way to start H2 Database from inside Quarkus application. I know it's possible to use @QuarkusTestResource(H2DatabaseTestResource.class)
for writing tests, however I'd need to use H2 in the main application. Is it a good strategy to use lifecycle methods to start/stop the H2 Database?
@ApplicationScoped
public class ApplicationLifecycle {
Server server;
void onStart(@Observes StartupEvent event) {
server = Server.createTcpServer("-tcpPort", "9092", "-tcpAllowOthers").start();
}
void onStop(@Observes ShutdownEvent event) {
server.stop;
}
}
Is there any better option? Thanks!