title: How to register an existing bean in Application context and what is the advantage I get out of it?
body: <p>I am a newbie to Spring. I was going through spring documentation where it says we can register existing objects created outside spring container in application context. I did that like this</p>
  
  <pre><code>OutsideBean outsideBean = new OutsideBean();
  ConfigurableApplicationContext applicationContext = 
      new ClassPathXmlApplicationContext("spring.xml");
  // SpringBean is the bean which is defined in spring.xml
  SpringBean springBean = applicationContext.getBean("springBean", SpringBean.class); 
  ConfigurableListableBeanFactory configurableListableBeanFactory =
      applicationContext.getBeanFactory();
  configurableListableBeanFactory.registerSingleton("outsideBean", outsideBean);
  </code></pre>
  
  <p>I have many unanswered questions here.</p>
  
  <ol>
  <li>The way I am doing above, is it correct.? </li>
  <li>Even if it is correct, is it the best way to do that.?</li>
  <li>What if I have to register a bean as a 'prototype'.?</li>
  <li>By registering my bean in application context what is the advantage I get out of it.?</li>
  </ol>
  
  <p>I read through many links in stackoverflow but couldnt understand it. Hence asking it in new thread.</p>