Announcement Announcement Module
No announcement yet.
Failure to unregister the MySQL JDBC Driver Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Failure to unregister the MySQL JDBC Driver

    After upgrading to Apache Tomcat/6.0.26 I've encountered a problem when closing the application:

    05-04-2010 16:48:01 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
    SEVERE: A web application registered the JBDC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
    My system:
    Apache Tomcat/6.0.26 - 1.6.0_18-b07 - Windows 7 6.1 amd64
    My data source is defined as follows:

        <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
            <property name="driverClassName" value="${jdbc.driver}" />
            <property name="url" value="${jdbc.url}" />
            <property name="username" value="${jdbc.username}" />
            <property name="password" value="${jdbc.password}" />
            <property name="validationQuery" value="SELECT 1" />
            <property name="testOnBorrow" value="true" />
    I'm using the MySQL JDBC driver and the latest version of the Spring Framework.

    Is this a problem with the Spring Framework or am I not using it correctly? I suppose I could manually unregister the driver upon shutdown.

    Any tips/help is much appreciated.

  • #2
    Tomcat 7 fails to unregister mySqlDriver

    Hi all,

    I am getting the same error when unregistering the mysql driver used in Spring security. I am using Spring Security 3.0.3 and Tomcat 7. Any help on this?



    • #3
      The source of this error is probably unproper connection and/or transaction management...don't mess around with connections yourself but use Spring's jdbc or orm support for database accessibility, and properly configure transactions using @Transactional.


      • #4
        Mysql connector

        Hi Enrico,

        Thanks for your response. I haven't written any class that access to the databases. Actually, what I've done is simply configure Spring's security to access to my authentication db which holds the users and passwords to authenticate. Everything is left to spring's control. Here is the bit from my security configuration file:

        <bean id="mysqlDataSource" class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost:3306/FedoraAuthentication" />
        <property name="username" value="fedoraAdmin" />
        <property name="password" value="dynamic" />



        • #5

          from the bit of xml configuration you posted, I can see you have configured a data source bean...I'm curious about how you use that bean (for example are you injecting the data source in a JdbcTemplate ? Or what? In any case, if you haven't already you should activate proper transaction management associating it with your data source, as you can read in the official Spring 3 documentation.


          • #6
            MySql Connector

            Hi Enrico,

            I am using that datasource as follows:

            <security:authentication-manager alias="authenticationManager">
            <security:authentication-provider user-service-ref="userDetailsService" />

            <bean id="userDetailsService" class=" ls.jdbc.JdbcDaoImpl">
            <property name="dataSource" ref="mysqlDataSource" />

            So as you can see, I am not writing any methods myself to access to the database. I just use this bean for login purposes. If I needed to use the transactional annotations, do you mind posting a little example or just pointing to the bit in the official docs?

            Thanks a lot,


            • #7

              that's a basic standard Spring Security configuration you posted...everything should work as expected. If you don't use the dataSource anywhere else, you don't need transaction management as Spring security uses it internally.

              This seems to me an issue related to the jdbc driver you use and your application server (the container); my suggestion is to try to switch to a container-managed DataSource and link it to Spring via jndi using the j2ee: namespace. This way the full life cycle of the resource will be managed by the app server and it surely won't have problems in cleaning it up for garbage collection.

              If you're interested in Spring's transaction management mechanics (you probably will need it sooner or later) you can read the official Spring 3 documentation, chapter 10 (pages 296-331) and especially paragraph 10.5 on annotated transactions.


              • #8
                Hi again,

                Thanks a lot for your response. I will give a look to the container managed option.



                • #9
                  To answer the question from the original post: this appears to be a problem with DBCP. See for more information.


                  • #10
                    One valid solution to this might be to move your JDBC drivers to the tomcat (common classloader) lib directory. (Defined in the file, usually CATALINA_HOME/lib). This way the common classloader loads the driver and there should be no problem with your webapp classloader.

                    My preliminary tests look ok. The message disappeared and the app is still working

                    BTW: you might also want to have a look at the jdbc-pool which is shipped with tomcat:
                    Last edited by nitegate; Dec 16th, 2010, 03:29 AM. Reason: more info


                    • #11
                      I can confirm that moving my jdbc jar to the tomcat common lib folder cleaned up the warning for me.

                      Also, for more info for Googlers who find this: