通过Spring以服务器模式启动H2数据库
我正在尝试通过 Spring 以服务器模式启动 H2 数据库(我希望它在不同的进程中运行)。 目前我正在使用 java Runnable.exec 启动 h2 数据库(使用命令:“java -cp h2.jar org.h2.tools.Server”)
我知道有一种方法可以通过 Spring 来完成。我尝试将以下内容添加到 spring 配置中,但它不起作用(它没有启动 H2 数据库):
<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'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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是否有: ?
你的 Spring 配置文件中
Do you happen to have:
in your Spring configuration files?
最近我必须做相同的配置来进行单元测试和检查数据,这对我有用(Spring 3.1.4)。然后,您只需连接 jdbc:h2:tcp://localhost:8043/mem:test 并确保在测试结束时添加 while(true){} 。
Recently I had to do the same configuration to make unit test and check data, this works for me (Spring 3.1.4). Then you just have to connect with jdbc:h2:tcp://localhost:8043/mem:test and make sure to put a while(true){} at the end of your test.
您确定确实调用了
Server
类中的createTcpServer
方法吗?您是否尝试过在那里设置断点?H2 教程 声称如何以编程方式创建和启动服务器:
您的 Spring 定义似乎模仿相同的初始化。但你总是可以尝试手动执行 - 也许这是 Spring 配置中的一些错误。
编辑:
我已经尝试过你的配置,它对我有用。是什么让您认为服务器未启动?它不会在标准输出上打印任何内容,但该进程会侦听 8043 端口。所以看起来还不错。
Are you sure the
createTcpServer
method in theServer
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:
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.