Right now I have one bean with the @Scheduled method working fine; it is declared in my context.xml application.
<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 plan another method (e.g. load some annotated class and inject its dependencies) on request. Sort of:
WebApplicationContext ctx = ContextLoader.getCurrentWebApplicationContext(); BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(NonWorkingBean.class); // add DAO references... ctx.registerBeanDefinition("nonWorkingBean", builder.getBeanDefinition()); // <-- this doesn't work
Obviously, this does not work because the XmlWebApplicationContext is read-only and does not have a registerBeanDefinition method. Is there any other way to achieve this?
I am using Tomcat 6.0.29 and Spring 3.0.4
source share