title: how to dynamic register spring bean and set as primary
body: <p>It's easy to register. 
  Just need to call <code>beanFactory.registerSingleton(beanName, object);</code>.</p>
  
  <p>But <code>beanFactory.getBeanDefinition(beanName).setPrimary(true)</code> will throw <strong>NPE</strong>.</p>
  
  <p><strong>So how to dynamically register spring bean and set as primary?</strong></p>