title: Java Spring Recreate specific Bean
body: <p>I want to re-create (new Object) a specific bean at Runtime (no restarting the server) upon some DB changes. This is how it looks - </p>
  
  <pre><code>@Component
  public class TestClass {
  
      @Autowired 
      private MyShop myShop; //to be refreshed at runtime bean
  
      @PostConstruct //DB listeners
      public void initializeListener() throws Exception {
          //...
          // code to get listeners config
          //...
  
          myShop.setListenersConfig(listenersConfig);
          myShop.initialize();
      }
  
      public void restartListeners() {
          myShop.shutdownListeners();
          initializeListener();
      }
  }
  </code></pre>
  
  <p>This code does not run as <code>myShop</code> object is created by Spring as Singleton &amp; its context does not get refreshed unless the server is restarted. How to refresh (create a new object) <code>myShop</code> ?</p>
  
  <p>One bad way I can think of is to create new <code>myShop</code> object inside <code>restartListeners()</code> but that does not seem right to me.</p>