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

  • Home
  • SEARCH
  • 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 6014981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:46:13+00:00 2026-05-23T02:46:13+00:00

I have a singleton bean that is being destroyed when the ApplicationContext is being

  • 0

I have a singleton bean that is being destroyed when the ApplicationContext is being refreshed. This bean is the session registry, which keeps track of sessions (duh). I use the refresh from the ApplicationContext to get the new configuration after my application has been initially configured. However, the SessionRegistry should NOT be destroyed since the session itself has not ended. Thus, I need to exclude the SessionRegistry from the wanton destruction caused by ApplicationContext’s refresh. Is there a reasonably simple way to do this, or must I implement my own version of the ApplicationContext, and recode its methods?

EDIT: So what I ended up doing was overriding the sessionregistry to make a true singleton, getting all the sessions from the session registry, removing the sessionregistry as a listner from the applicationcontext, and then adding the sessions back in after the sessionregistry was recreated.

  • 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-05-23T02:46:14+00:00Added an answer on May 23, 2026 at 2:46 am

    I guess you can use @PreDestroy method to transfer the current state to a static field, and read that field on @PostConstruct to restore the bean data.

    Note that spring beans are singleton within the context. If the context dies, the bean dies. And a bean can have multiple instances if multiple contexts exists. Hence the use of static which is “more singleton”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a singleton spring bean that is being invoked in response to some
I have a singleton bean which needs for each call of a function to
Assume that we have Spring bean UserController with singleton scope. All my further reasoning
I have a Spring MVC app where I am using a singleton bean that
I have a spring bean that I have configured in applicationContext like below: <bean
I have a singleton that uses the static readonly T Instance = new T();
I have a C# singleton class that multiple classes use. Is access through Instance
I have a co-worker that swears by //in a singleton Constants class public static
I have a singleton ejb which is getting initialised twice. I have no idea
I have a hierarchy of application contexts. The bean that is defined in the

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.