views:

922

answers:

2

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 org.h2.tools.Server")

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="org.h2.tools.Server" class="org.h2.tools.Server"
     factory-method="createTcpServer" init-method="start" destroy-method="stop">
     <constructor-arg value="-tcp,-tcpAllowOthers,true,-tcpPort,8043" />
    </bean>

    <bean id="org.h2.tools.Server-WebServer" class="org.h2.tools.Server"
     factory-method="createWebServer" init-method="start">
     <constructor-arg value="-web,-webAllowOthers,true,-webPort,8082" />
    </bean>

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:

import org.h2.tools.Server;
...
// start the TCP Server
Server server = Server.createTcpServer(args).start();
...
// stop the TCP Server
server.stop();

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.

EDIT:

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!
Li
+1 good catch...
skaffman