Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8007845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:57:26+00:00 2026-06-04T17:57:26+00:00

When is a Spring container (XMLBeanFactory) gracefully unloaded by Spring? What happens when the

  • 0
  1. When is a Spring container (XMLBeanFactory) gracefully unloaded by Spring?
  2. What happens when the application is running but the only handler to the BeanFactory goes out of scope?
  3. What is the ideal way to load a Spring Container? Is doing handler = new BeanFactory() the right approach?

Update:
When container goes out of scope, we would indeed expect the close() method to be called which would in turn release all the held resources. But that does not happen! I encountered a case where I had spring containers going out of scope but still memory getting full (OutOfMemory error). The reason was that the SessionFactory objects created by my Spring containers never got garbage collected as they are created as static. This implies that close()->destroy() was never called when containers went out of scope. Makes me believe that there is a leak issue with Spring itself.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T17:57:27+00:00Added an answer on June 4, 2026 at 5:57 pm
    1. This depends on how you’re instantiating it. I a webapp, this is typically done at context shutdown. On the command line, you have to specifically close the context (via the “close” method on “AbstractApplicationContext”
    2. Same as anything else that falls out of scope. Not sure if the “close” method is part of the finalizer phase or not. I would hope the finalizer would trigger the destroy phase.
    3. As someone else said, don’t use BeanFactory directly. Create an ApplicationContext. The most common way for web apps is the ContextLoaderListener, and for command line programs would be ClassPathXmlApplicationContext.

    // Keep a specific type, so we can call the “close” method later since
    it’s // not part of the ApplicationContext interface itself.
    ClasspathXmlApplicationContext context =
    new ClasspathXmlApplicationContext(new String[] { “applicationContext.xml });

    and then later on you close it:

    context.close();
    

    For webapps:

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>
    
    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a portlet application. It is configured using Spring framework IoC container. I
How do you configure a Spring bean container (or application context) to load a
I have used Spring before but I am no expert and only used it
If an application is managed by the Spring container, can a developer still use
I'm currently searching for replacement for Spring IoC container. I like Spring, but it
Does a Spring Container running in an Appserver have a separate classloader? If it
I'm running embedded jetty inside of a spring ioc container. The spring ioc contains
I have a cluster of servers running a spring application. Some of the spring
I'm currently migrating a Spring application from the JBoss J2EE container to Sun's Glassfish
I have a small application that doesn't use Spring container. Now there's a need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.