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?
java spring tomcat postgresql c3p0
mmalmeida Aug 10 '17 at 18:29 2017-08-10 18:29
source share