Announcement Announcement Module
No announcement yet.
Connection Leaks, obtaining a new bean factory Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Connection Leaks, obtaining a new bean factory


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



    • #3
      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:

      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.