Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Failure to unregister the MySQL JDBC Driver

  1. #1
    Join Date
    Nov 2009
    Posts
    3

    Default Failure to unregister the MySQL JDBC Driver

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

    Code:
    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:
    Code:
    Apache Tomcat/6.0.26 - 1.6.0_18-b07 - Windows 7 6.1 amd64
    My data source is defined as follows:

    Code:
        <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" />
        </bean>
    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. #2
    Join Date
    Sep 2010
    Location
    Liverpool, UK
    Posts
    4

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

    Thanks,
    Agus

  3. #3
    Join Date
    Jul 2010
    Location
    Venice, Italy
    Posts
    709

    Default

    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. #4
    Join Date
    Sep 2010
    Location
    Liverpool, UK
    Posts
    4

    Default 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" />
    </bean>

    Thanks,
    Agustina

  5. #5
    Join Date
    Jul 2010
    Location
    Venice, Italy
    Posts
    709

    Default

    Hi,

    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. #6
    Join Date
    Sep 2010
    Location
    Liverpool, UK
    Posts
    4

    Default MySql Connector

    Hi Enrico,

    I am using that datasource as follows:

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

    <bean id="userDetailsService" class="org.springframework.security.core.userdetai ls.jdbc.JdbcDaoImpl">
    <property name="dataSource" ref="mysqlDataSource" />
    </bean>

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

  7. #7
    Join Date
    Jul 2010
    Location
    Venice, Italy
    Posts
    709

    Default

    Hi,

    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. #8
    Join Date
    Sep 2010
    Location
    Liverpool, UK
    Posts
    4

    Default

    Hi again,

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

    Cheers,
    Agustina

  9. #9
    Join Date
    Sep 2008
    Posts
    2

    Default

    To answer the question from the original post: this appears to be a problem with DBCP. See https://issues.apache.org/jira/browse/DBCP-332 for more information.

  10. #10

    Default

    One valid solution to this might be to move your JDBC drivers to the tomcat (common classloader) lib directory. (Defined in the catalina.properties 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:
    http://www.tomcatexpert.com/blog/201...pooling-module
    Last edited by nitegate; Dec 16th, 2010 at 03:29 AM. Reason: more info

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •