有没有办法在Spring Batch中动态加载作业?
我使用Spring应用程序上下文运行应用程序
我想在运行时动态加载以下作业:
<batch:job id="MyJob">
<batch:description>MyJob Desc</batch:description>
<batch:step id="step0_PromotionFetch" >
<batch:tasklet ref="promotionFetch">
<batch:transaction-attributes
propagation="NEVER" />
</batch:tasklet>
</batch:step>
</batch:job>
我的代码:
DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) configurableApplicationContext.getBeanFactory();
GenericApplicationContext genericApplicationContext = new GenericApplicationContext();
XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader(genericApplicationContext);
xmlBeanDefinitionReader.loadBeanDefinitions(configXMLFileName);
BeanDefinition beanDefinition = xmlBeanDefinitionReader.getBeanFactory().getBeanDefinition("MyJob");
beanFactory.registerBeanDefinition("MyJob", beanDefinition);
我收到了错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#315': Cannot create inner bean '(inner bean)' of type [org.springframework.batch.core.job.flow.support.StateTransition] while setting bean property 'stateTransitions' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#315': Cannot create inner bean '(inner bean)' of type [org.springframework.batch.core.job.flow.support.state.StepState] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#315': Cannot resolve reference to bean 'step0_PromotionFetch' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'step0_PromotionFetch' is defined
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:282)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:126)
这是正确的方法吗?