H2 webserver failing on Jetty restart
We have our (new) build setup with the H2 web server starting up using the following Spring bean:
<bean id="org.h2.tools.Server-WebServer" class="org.h2.tools.Server"
factory-method="createWebServer" depends-on="dataSource" init-method="start"
lazy-init="false">
<constructor-arg value="-web,-webPort,8082" />
</bean>
This works fine for the other three developers (who all run a Mac or Linux), but poor me on my Windows laptop gets into trouble whenever Jetty restar开发者_高级运维ts after finding a change in the code:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'org.h2.tools.Server-WebServer' defined in ServletContext resource [/WEB-INF/spring/appServlet/controllers.xml]:
Invocation of init method failed; nested exception is org.h2.jdbc.JdbcSQLException:
Exception opening port "8082" (port may be in use), cause: "java.net.BindException: Address already in use: JVM_Bind" [90061-154]
The theory is that the port is not properly released when Jetty signals the restart, and/or H2 doesn't re-use the port.
Now my question: How can I fix this? I figured it'd be a common problem, but I couldn't find anything about it.
Looking at your configuration it seems you are missing a destroy-method attribute. Try this:
<bean id="org.h2.tools.Server-WebServer" class="org.h2.tools.Server"
factory-method="createWebServer"
depends-on="dataSource"
init-method="start"
destroy-method="stop"
lazy-init="false">
<constructor-arg value="-web,-webPort,8082" />
</bean>
精彩评论