Where to install c3p0 dependency in Tomcat container

I had the impression that the libraries for the database driver ( postgres-xxjar 'in my case) and the connection pool ( c3p0 ) should have been in the lib container (for example, for Tomcat7, $CATALINA_HOME/lib ).

However, the official documentation of C3p0 does not provide any information on how to put a jar of connection pool into a container, war of use:

Put the files lib / c3p0-0.9.5.2.jar and lib / mchange-commons-java-0.2.11.jar somewhere in your CLASSPATH (or anywhere else where your application class loader finds it). It!

The current problem in the new tomcat installation (j ava.lang.NoClassDefFoundError: com/mchange/v2/ser/Indirector , when I have m change-commons-java dependency in the application WAR and c3p0 dependencies in $CATALINA_HOME/lib ) made me back to this, but I can’t find reliable information on where to place these libraries.

Normal application configuration
In my case, c3p0 configuration c3p0 done via spring bean in the class path of the application:

 <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> 

If I have several applications in one Tomcat container, each will have one c3p0 bean, as was the case in his war.

Memory leaks?

The assumption that postgres.jar and c3p0.jar in the lib/ container, and not in war, was that the latter caused a memory leak.

Postgres driver leak

This user indicates that JDBC drivers register themselves in the JVM-wide singleton DriverManager which is shared by all web apps. If you have the same (as in class name) JDBC driver register twice from two different web apps, this might cause your problem. This is even more problematic if your web apps use different versions of the same JDBC driver. JDBC drivers register themselves in the JVM-wide singleton DriverManager which is shared by all web apps. If you have the same (as in class name) JDBC driver register twice from two different web apps, this might cause your problem. This is even more problematic if your web apps use different versions of the same JDBC driver.

Leak in c3p0 We have moved c3p0 to $CATALINA_HOME/lib after https://stackoverflow.com/a/169449/ (we had a similar warning when deploying the application).

Should they be in Tomcat or in the lib / application?

+1
java spring tomcat postgresql c3p0
Aug 10 '17 at 18:29
source share
1 answer

Whether you need to place the jar in the Tomcat lib directory depends on whether Tomcat should know about it or not. And it depends on how you set things up.

Typically, if you mention a class in the Tomcat configuration file, then this class (and those on which it depends) should be in the Tomcat lib directory.

For example, if you configure your DataSource in Tomcat configuration files, you need to make your driver class available to Tomcat. If instead you configure your DataSource in your application code, then you will not.

You do not indicate how you configure C3P0, so we cannot tell you where the bank should be. Of course, if Tomcat needs it, and it is not there, then you should expect the log to be locked and everything will not work correctly.

0
Aug 10 '17 at 18:38 on
source share
β€” -



All Articles