title: Programmatically set a specific bean object - Spring DI
body: <p>In my program I need to programmatically configure an ApplicationContext. Specifically, I have a reference to an instance of MyClass and I want to define it as a new bean called "xxyy".</p>
  
  <pre><code>public void f(MyClass mc, ApplicationContext ac) {
    // define mc as the "xxyy" bean on ac ???
    ...
    ...
  
    // Now retrieve that bean
    MyClass bean = (MyClass) ac.getBean("xxyy");
  
    // It should be the exact same object as mc
    Assert.assertSame(mc, bean); 
  }
  </code></pre>
  
  <p>The BeanDefinition API let's me specify the class of the new bean, so it does not work for me since I want to specify the instance. 
  I managed to find a solution but it took two additional factory beans which seems like too much code for such an eartly purpose. </p>
  
  <p>Is there a standard API that addresses my needs?</p>