I'm trying to start the H2 database in server mode (I want it to run in a different process) via Spring. Currently I'm using java Runnable.exec to start the h2 database (using the command: "java -cp h2.jar")

I know that there is a way to do it via Spring. I tried to add the following to the spring configuration, but it didn't work (it didn't start the H2 database):

    <bean id="" class=""
     factory-method="createTcpServer" init-method="start" destroy-method="stop">
     <constructor-arg value="-tcp,-tcpAllowOthers,true,-tcpPort,8043" />

    <bean id="" class=""
     factory-method="createWebServer" init-method="start">
     <constructor-arg value="-web,-webAllowOthers,true,-webPort,8082" />

I would appreciate any help/ideas

+1  A: 

Are you sure the createTcpServer method in the Server class is really called? Have you tried setting up a breakpoint there?

H2 tutorial claims this how you can create and start the server programmatically:

// start the TCP Server
Server server = Server.createTcpServer(args).start();
// stop the TCP Server

Your Spring definition seems to mimick the same initialization. But you can always try doing it manually - maybe it's some fault in Spring configuration.


I've tried your configuration and it works for me. What makes you think the server is not started? It doesn't print out anything on stdout, however the process listens at the 8043 port. So it seems pretty OK.

Grzegorz Oledzki
+4  A: 

Do you happen to have:

<beans default-lazy-init="true" ...

in your Spring configuration files?

Grzegorz Oledzki
I changed the beans configuration to lazy-init="false".It works now. Thanks you!
+1 good catch...