将c3p0依赖项放在Tomcat容器中的位置 [英] Where to put c3p0 dependency in Tomcat Container

查看:172
本文介绍了将c3p0依赖项放在Tomcat容器中的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的印象是,数据库驱动程序(在我的情况下为 postgres-xxjar ')和连接池( c3p0 )必须驻留在容器的lib中(例如,对于Tomcat7, $ CATALINA_HOME / lib )。

I was under the impression that the libraries for both the database driver (postgres-x.x.jar'in my case) and the connection pooler (c3p0) had to reside in the container's lib (e.g. for Tomcat7, $CATALINA_HOME/lib).

但是,C3p0官方文档未提供任何信息关于将连接池的jar放入容器与在应用程序的战争中进行比较:

However, the official C3p0 documentation doesn't provide any information with regards to put the connection pool's jar in the container vs having it in the application's war:


将文件lib / c3p0-0.9放置。 5.2.jar和lib / mchange-commons-java-0.2.11.jar在CLASSPATH中的某个位置(或应用程序的类加载器将找到它的任何其他位置)。而已!

Place the files lib/c3p0-0.9.5.2.jar and lib/mchange-commons-java-0.2.11.jar somewhere in your CLASSPATH (or any other place where your application's classloader will find it). That's it!

新的tomcat安装中的当前问题(j ava.lang.NoClassDefFoundError:com / mchange / v2 / ser / Indirector ,当我在应用程序的WAR中具有m change-commons-java依赖项 c3p0 < $ CATALINA_HOME / lib 中的/ code>依赖性使我重新审视了此信息,但是我找不到有关将这些库放在何处的任何权威信息。

A current issue in a new tomcat installation (java.lang.NoClassDefFoundError: com/mchange/v2/ser/Indirector, when I have the mchange-commons-java dependency in the application's WAR and the c3p0 dependency in $CATALINA_HOME/lib) made me revisit this, but I can't find any authoritative information regarding where to put these libraries.

常规应用程序配置

在我的情况下,进行了 c3p0 配置通过应用程序的类路径中的spring bean:

Usual application configuration
In my case the c3p0 configuration is made via spring bean within the application's classpath:

<bean id="c3p0DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
        scope="singleton" destroy-method="close">
        <property name="driverClass">
            <value>org.postgresql.Driver</value>
        </property>
        <property name="jdbcUrl">
            <value>${jdbc.url}</value>
        </property>
        <property name="user">
            <value>${jdbc.user}</value>
        </property>
        <property name="password">
            <value>${jdbc.pw}</value>
        </property>
        ...
<bean> 

如果同一个 Tomcat中有多个应用程序容器,每个容器中都会有一个c3p0 bean,像这样包含在其war中。

If I have multiple applications in the same Tomcat container, each will have one c3p0 bean like this contained in its war.

内存泄漏?

具有 postgres.jar c3p0.jar 放在容器的 lib / 中,而不是战争是后者会导致内存泄漏。

The assumption for having the postgres.jar and c3p0.jar in the container's lib/ and not in the war was that the latter would cause memory leaks.

Postgres驱动程序中的泄漏

此用户声明 JDBC驱动程序在JVM范围内的Singleton DriverManager中进行注册,该驱动程序由共享所有网络应用。如果您具有相同的(与类名相同)JDBC驱动程序从两个不同的Web应用程序注册了两次,则可能会导致您的问题。如果您的Web应用程序使用同一JDBC驱动程序的不同版本,这甚至会更加成问题。

c3p0泄漏
对此Stackoverflow的评论之后,我们将c3p0移至了 $ CATALINA_HOME / lib (在取消部署应用程序时,我们也会收到类似的警告)。

Leak in c3p0 We moved c3p0 to $CATALINA_HOME/lib after this comment on Stackoverflow (we had a similar warning when undeploying an application).

它们应该驻留在Tomcat还是应用程序的lib /中?

Should they reside in Tomcat or the application's lib/ ?

推荐答案

是否需要在Tomcat的lib目录中放置一个jar取决于Tomcat是否需要了解它。

Whether or not you need to put a jar in Tomcat's lib directory depends on whether Tomcat needs to know about it or not. And that depends on how you are configuring things.

作为一般规则,如果要在Tomcat配置文件中提及一个类,则该类(以及该类中的那个

As a general rule, if you are mentioning a class in a Tomcat config file, then that class (and those that it depends on) must be in Tomcat's lib directory.

例如,如果您在Tomcat的配置文件中配置DataSource,则需要使驱动程序类对Tomcat可用。相反,如果您在应用程序的代码中配置DataSource,则您不必这样做。

For example, if you configure your DataSource in Tomcat's config files, then you need to make your driver class available to Tomcat. If instead you configure your DataSource within your application's code then you do not.

您没有指定配置C3P0的方式,因此我们无法告诉您jar需要在哪里进行配置。是。当然,如果Tomcat需要它并且它不在那儿,那么您应该期望看到记录了一个异常,并且一切无法正常进行。

You do not specify how you are configuring C3P0, so we cannot tell you where the jar needs to be. Of course, if Tomcat needs it and it is not there, then you should expect to see an exception logged and things won't work properly.

这篇关于将c3p0依赖项放在Tomcat容器中的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆