春天脱离德比

发布于 2024-09-08 09:49:00 字数 938 浏览 1 评论 0原文

我在 Tomcat 上运行的 Web 应用程序中使用 Apache Derby 和 Spring JdbcTemplate。

Spring负责管理数据源。我注意到,如果我更新 .war 文件并且 Tomcat 取消部署/重新部署应用程序,则会收到此错误:

java.sql.SQLException: Another instance of Derby may have already booted the database /tmp/manager_db/manager.

重新启动 Tomcat 可以解决问题,但作为纯粹主义者,我想在取消部署 Web 应用程序时正确清理内容。

嵌入式驱动程序似乎没有“关闭”方法来将 bean 声明放入“destroy-method”下。我知道关闭通常是使用“shutdown”连接 URL“jdbc:derby:;shutdown=true”来实现的。

有什么建议吗?

这是我的数据源的 Spring 配置文件中的声明(数据库不会位于 /tmp/ 下,暂时就在那里)。

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="org.apache.derby.jdbc.EmbeddedDriver"/>
    <property name="url" value="jdbc:derby:/tmp/manager_db/manager;create=true"/>
    <property name="username" value=""/>
    <property name="password" value=""/>
</bean>

I'm using Apache Derby with the Spring JdbcTemplate inside a web app running on Tomcat.

Spring is managing the data source. I've noticed that if I update the .war file and Tomcat undeploys/redeploys the app, I get this error:

java.sql.SQLException: Another instance of Derby may have already booted the database /tmp/manager_db/manager.

Restarting Tomcat fixes the problem, but as a purist, I'd like to clean things up properly when the webapp is undeployed.

The Embedded driver doesn't seem to have a 'close' method to put in the bean declaration under 'destroy-method'. I know the shutdown is normally achieved using a 'shutdown' connection URL, "jdbc:derby:;shutdown=true".

Any suggestions?

Here's the declaration in the Spring config file for my data source (the db won't be under /tmp/, just there for now).

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="org.apache.derby.jdbc.EmbeddedDriver"/>
    <property name="url" value="jdbc:derby:/tmp/manager_db/manager;create=true"/>
    <property name="username" value=""/>
    <property name="password" value=""/>
</bean>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绿光 2024-09-15 09:49:00

我认为更好的答案是使用 Tomcat JNDI 数据Spring 的源池。 Spring 的 JDBC 模板将在完成后将连接返回到池中。

I think a better answer is to use the Tomcat JNDI data source pool with Spring. Spring's JDBC template will return the connection to pool when it's done.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文