Results 1 to 3 of 3

Thread: Connection Leaks, obtaining a new bean factory

  1. #1
    Join Date
    Aug 2004
    Posts
    8

    Default Connection Leaks, obtaining a new bean factory

    Hi

    I am Spring newbie - so forgive any clueless questions :-)

    When my units tests are run on Weblogic (via Cactus) - Weblogic is reporting connection pool leaks (manifested when the app attempts to create a new DAO bean).

    I *think* I know what the problem is - but I dont know the best way to fix it.

    I am obtaining the app context via a static factory class (calls ClassPathXmlApplicationContext). Once the factory has been created, I hang on to the static reference - and use that to create all my beans.


    My naive assumption was that the factory would only get created once (this is indeed the case when I run my test code out of container) - but from my log files I can see that Weblogic runs the static code several times (appears to be every time a new cactus test servlet is run). I suspect this is causing the connection leaks? Weblogic must be creating a new classloader every time the test servlet runs?

    So what I want is for the factory to be created only once.

    I have read about the using web.context.ContextLoaderListener - but my challlenge is this a layered application - and my backend tier doesnt have access to the servlet context.

    How can I ensure that only one factory gets created, and how can I access that factory in my backend tier (without having acess to the servlet context).


    Any pointers/suggestions welcome

  2. #2
    Join Date
    Aug 2004
    Posts
    8

    Default

    Repling to my own post...

    I didnt see any easy way around this problem - so I spent the last 8 hours refactoring my code to get rid of the static method to get the the ApplicationContext (I now get it via the Web Container).

    Things seem to be working now (no more Weblogic complaints about connection leaks...)

    Warren

  3. #3
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    If you actually need a singleton style access to an appcontext or beanfactory, there are some convenience classes for this available in Spring, basically implementations of the BeanFactoryLocator interface, as described here:
    http://www.springframework.org/docs/...s.html#d0e2041

    It is however highly recommended that anything like this be used for glue code only. 99% of your code should not even know about the appcontext/beanfactory.

    Regards,
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

Similar Threads

  1. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  2. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  3. Stack Overflow
    By rayho222 in forum Container
    Replies: 6
    Last Post: May 17th, 2005, 03:42 AM
  4. could not satisfy dependencies
    By springuser in forum Container
    Replies: 4
    Last Post: Apr 26th, 2005, 01:15 PM
  5. Replies: 1
    Last Post: Apr 25th, 2005, 07:37 PM

Posting Permissions

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