我有第一步是xml架构验证的场景,我已经使用tasklet来使用ref =" beanId"来验证xml对模式,请注意这里没有处理任何块。下一步是使用块,即读取器,处理器和写入器配置。如果我执行模式验证tasklet并且接下来,我会收到IllegalArgument异常。 " nextStep"是大块头。例外情况是Step [nextStep]同时包含一个元素和一个' ref'属性引用Tasklet。 ' nextStep' defination有chunk但不是ref元素。完整的代码如下。
案例1 - 如果使用以下配置执行作业,则其工作正常,但我需要在架构验证后处理xml中的数据。案例2是不公平的情况。不确定什么是错的。在仅在tasklet之后的chuck执行步骤时,它是否在弹簧批处理中无效?
<batch:job id="DataEnhancement" job-repository="jobRepository">
<!-- 1. Validate Input file against schema, if validation fails, notify
error -->
<batch:step id="validateSchema">
<tasklet ref="SchemaValidatorTasklet" transaction-manager="hibernateTransactionManager"/>
<batch:end on="*" />
<batch:next on="FAILED" to="generateErrorResponseXml" />
</batch:step>
<!-- 9. Generate response xml for schema validation failure. -->
<batch:step id="generateErrorResponseXml" parent="validateSchema">
<tasklet ref="schemaValidationErrorXmlTasklet"
allow-start-if-complete="true" />
<batch:next on="*" to="notifyError" />
</batch:step>
<!-- 10. Error notification tasklet to notify error. TODO : No requirements
on error notifications -->
<batch:step id="notifyError">
<tasklet ref="notifyFailureTasklet" allow-start-if-complete="true" />
<batch:fail on="*" exit-code="FAILED" />
</batch:step>
</batch:job>
Case 2 - I have added readHeader step after validateSchema step, modified configuration is as below.
<batch:job id="DataEnhancement" job-repository="jobRepository">
<!-- 1. Validate Input file against schema, if validation fails, notify
error -->
<batch:step id="validateSchema">
<tasklet ref="SchemaValidatorTasklet" transaction-manager="hibernateTransactionManager"/>
<!-- <batch:end on="*" /> -->
<batch:next on="*" to="readHeader" />
<batch:next on="FAILED" to="generateErrorResponseXml" />
</batch:step>
<!-- 2. Read PDE header details and persist into stage tables -->
<batch:step id="readHeader" parent="validateSchema">
<batch:tasklet transaction-manager="hibernateTransactionManager">
<batch:chunk reader="xmlHeaderReader" processor="HeaderProcessor"
writer="hibernateItemWriter" commit-interval="1" />
</batch:tasklet>
<batch:end on="*" />
<!-- <batch:next on="*" to="readPdeTrailer" /> -->
<batch:next on="FAILED" to="notifyError" />
</batch:step>
<!-- 9. Generate response xml for schema validation failure. -->
<batch:step id="generateErrorResponseXml" parent="validateSchema">
<tasklet ref="schemaValidationErrorXmlTasklet"
allow-start-if-complete="true" />
<batch:next on="*" to="notifyError" />
</batch:step>
<!-- 10. Error notification tasklet to notify error. TODO : No requirements
on error notifications -->
<batch:step id="notifyError">
<tasklet ref="notifyFailureTasklet" allow-start-if-complete="true" />
<batch:fail on="*" exit-code="FAILED" />
</batch:step>
</batch:job>
获取以下stacktrace
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'DataEnhancement': Cannot create inner bean '(inner bean)#47634763' of type [org.springframework.batch.core.configuration.xml.SimpleFlowFactoryBean] while setting bean property 'flow'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#47634763': Cannot create inner bean '(inner bean)#27b627b6' of type [org.springframework.batch.core.job.flow.support.StateTransition] while setting bean property 'stateTransitions' with key [2]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#27b627b6': Cannot create inner bean '(inner bean)#7d267d26' 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)#7d267d26': Cannot resolve reference to bean 'readHeader' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'readHeader': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: Step [readHeader] has both a <chunk/> element and a 'ref' attribute referencing a Tasklet.
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:290)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:129)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1456)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1197)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:684)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
at com.batch.app.XmlReadHibernateWriteBatchApplication.main(XmlReadHibernateWriteBatchApplication.java:36)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#47634763': Cannot create inner bean '(inner bean)#27b627b6' of type [org.springframework.batch.core.job.flow.support.StateTransition] while setting bean property 'stateTransitions' with key [2]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#27b627b6': Cannot create inner bean '(inner bean)#7d267d26' 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)#7d267d26': Cannot resolve reference to bean 'readHeader' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'readHeader': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: Step [readHeader] has both a <chunk/> element and a 'ref' attribute referencing a Tasklet.
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:290)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:129)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:359)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:157)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1456)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1197)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:276)
... 15 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#27b627b6': Cannot create inner bean '(inner bean)#7d267d26' 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)#7d267d26': Cannot resolve reference to bean 'readHeader' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'readHeader': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: Step [readHeader] has both a <chunk/> element and a 'ref' attribute referencing a Tasklet.
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:290)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:129)
at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:632)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:442)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1094)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:989)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:276)
... 23 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#7d267d26': Cannot resolve reference to bean 'readHeader' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'readHeader': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: Step [readHeader] has both a <chunk/> element and a 'ref' attribute referencing a Tasklet.
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:336)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:632)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:140)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1114)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1017)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:276)
... 31 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'readHeader': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: Step [readHeader] has both a <chunk/> element and a 'ref' attribute referencing a Tasklet.
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:175)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:103)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1512)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:250)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
... 39 more
Caused by: java.lang.IllegalArgumentException: Step [readHeader] has both a <chunk/> element and a 'ref' attribute referencing a Tasklet.
at org.springframework.util.Assert.isNull(Assert.java:89)
at org.springframework.batch.core.configuration.xml.StepParserStepFactoryBean.getObject(StepParserStepFactoryBean.java:268)
at org.springframework.batch.core.configuration.xml.StepParserStepFactoryBean.getObject(StepParserStepFactoryBean.java:113)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:168)
... 44 more
答案 0 :(得分:1)
&#34;读&#34;你的(未格式化的)堆栈跟踪问题在这里:
创建名称为&#39; readHeader&#39;:FactoryBean的bean时出错 对象创建异常;嵌套异常是 java.lang.IllegalArgumentException:Step [readHeader]都有一个 元素和&#39; ref&#39;引用Tasklet的属性
问题在于:
<batch:step id="readHeader" parent="validateSchema">
您从validateSchema
步继承步骤配置,其中包含对任务组的引用,readHeader
正在实现基于块的步骤。
删除parent="validateSchema"
,一切正常。