title: How can I register beans from Spring XML file at runtime?
body: <p>I want to register additional beans from a file with the Spring context at runtime. I followed an <a href="https://stackoverflow.com/questions/27580811/">example</a> with this code:</p>
  
  <pre><code>@Autowired
  private ApplicationContext applicationContext;
  
  private void loadBeans(String beansXml) {
      GenericApplicationContext createdContext =
              new GenericApplicationContext(applicationContext);
      XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(createdContext);
      reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
      reader.loadBeanDefinitions(new InputSource(new StringReader(beansXml)));
      createdContext.refresh();
  }
  </code></pre>
  
  <p>The passed XML string is actually processed by Spring, what I have verified by putting in an unresolveable reference about which Spring complained. However, when I trie to get a certain bean with</p>
  
  <pre><code>@Autowired
  ApplicationContext context;
  
  public void test() {
      context.getBean("myId");
  }
  </code></pre>
  
  <p>I get the following exception:</p>
  
  <pre><code>org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'myId' available
  </code></pre>
  
  <p>Spring version: 4.3</p>
  
  <p>What is missing or wrong?</p>