Right now I have one bean with a @Scheduled method working fine; it's declared in my applicationContext.xml.
<!-- some JPA stuff -->
<bean id="aWorkingBean" class="some.package.WorkingBean">
<property name="someDAO" ref="someDAO" />
</bean>
<task:annotation-driven scheduler="myScheduler" />
<task:scheduler id="myScheduler" pool-size="10" />
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:
WebApplicationContext ctx = ContextLoader.getCurrentWebApplicationContext();
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(NonWorkingBean.class);
// add DAO references...
ctx.registerBeanDefinition("nonWorkingBean", builder.getBeanDefinition()); // <-- this doesn't work
Obviously it doesn't work because the XmlWebApplicationContext is read-only and has no registerBeanDefinition method. Is there any other way to achieve this?
I'm using Tomcat 6.0.29 and Spring 3.0.4