springhttp-postsingletonjavabeansapplicationcontext

Does spring store updated singleton beans back to the ApplicationContext


Does spring application context get initialised for every http request ? In a spring web project If I modify a singleton bean in first http request then in the next http request can I get that value ?


Solution

  • Application Context is being initialised when the application starts. If you in any way modify a singleton bean you will get the updated value. Let's say you have a singleton object that has an integer field age = 10. And you create an endpoint to set this value and another one to fetch it. If you try to fetch it you'll get 10, but if you call an endpoint to change the value to 15 next time you fetch it you'll get 15.