h2 and spring

85 views
Skip to first unread message

Matthew

unread,
Dec 4, 2008, 3:47:11 PM12/4/08
to H2 Database
Hi everyone,

I have a Maven project. One of modules is a war. I wonder if I could
use H2 in that way:

1. DB is being started when test are launched (for example by Spring)
2. this DB is shutdown after test were executed
3. DB starts again when application is started (after deploy and
running container).

If DB is ready I wish I could connect to it with web console (I should
start web server)

I tried to do like this:
in spring context:
<!-- H2 Database - tcp server -->
<bean id="h2tcp" class="org.h2.tools.Server"
factory-method="createTcpServer" init-method="start" destroy-
method="stop">
<constructor-arg value="-tcp,-tcpAllowOthers,true" />
</bean>

<bean id="h2web" class="org.h2.tools.Server"
factory-method="createWebServer" init-method="start" destroy-
method="stop">
<constructor-arg value="-browser" />
</bean>

and my connection URL is like this:
jdbc:h2:tcp://localhost/mem:koszyki_postpaid;DB_CLOSE_DELAY=-1

but it doesn't work for me - connection refused when trying to do
something on entity manager.

If i try
jdbc:h2:mem:koszyki_postpaid;DB_CLOSE_DELAY=-1 everything work fine. I
can connect to my database from the other process than my app is
working on. Unfortunately, when I try to build my app by maven and
tests are executed - Adress already bind excpetion is being thrown. I
thing something is wrong with closing DB.

Please help me ;)
Matthew




Thomas Mueller

unread,
Dec 8, 2008, 1:40:13 PM12/8/08
to h2-da...@googlegroups.com
Hi,

> <bean id="h2web" class="org.h2.tools.Server"
> factory-method="createWebServer" init-method="start" destroy-
> method="stop">
> <constructor-arg value="-browser" />
> </bean>

createWebServer does not support the argument '-browser'. This is only
supported by the method Server.main(). See also the Javadocs.

> but it doesn't work for me - connection refused when trying to do
> something on entity manager.

Is there an exception? Could you post it please? Maybe the problem is
just the port number, or maybe you want to access it from another
machine (this is disabled by default).

> If i try
> jdbc:h2:mem:koszyki_postpaid;DB_CLOSE_DELAY=-1 everything work fine. I
> can connect to my database from the other process than my app is
> working on. Unfortunately, when I try to build my app by maven and
> tests are executed - Adress already bind excpetion is being thrown.

I get 'address already bound' if another process uses this port. Maybe
the (test) process is not stopped after maven is killed or finished?
Could you use 'jps -l' to find out if there is an old Java process
running before you start maven? If jps is not installed (needs Java
1.5) then you can use ps -ef (Linux) or the Task Manager (Windows).

Regards,
Thomas

Reply all
Reply to author
Forward
0 new messages