title: How to schedule a new method in a Spring enabled web app at runtime?
body: <p>Right now I have one bean with a @Scheduled method working fine; it's declared in my applicationContext.xml.  </p>
  
  <pre><code>&lt;!-- some JPA stuff --&gt;
  
  &lt;bean id="aWorkingBean" class="some.package.WorkingBean"&gt;
      &lt;property name="someDAO" ref="someDAO" /&gt;
  &lt;/bean&gt;
  
  &lt;task:annotation-driven scheduler="myScheduler" /&gt;
  &lt;task:scheduler id="myScheduler" pool-size="10" /&gt;
  </code></pre>
  
  <p>What I'm trying to do is programmatically schedule another method (e.g. loading some annotated class and inject its dependencies) upon request. Something like:</p>
  
  <pre><code>WebApplicationContext ctx = ContextLoader.getCurrentWebApplicationContext();
  BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(NonWorkingBean.class);
  // add DAO references...
  ctx.registerBeanDefinition("nonWorkingBean", builder.getBeanDefinition()); // &lt;-- this doesn't work
  </code></pre>
  
  <p>Obviously it doesn't work because the XmlWebApplicationContext is read-only and has no <em>registerBeanDefinition</em> method. Is there any other way to achieve this?</p>
  
  <p>I'm using Tomcat 6.0.29 and Spring 3.0.4</p>