2013-07-09 94 views
1

我从链接 https://stackoverflow.com/q/15784984/814074读取了一个问题,并尝试了上述链接中给出的解决方案。在Spring批处理中将作业参数传递给bean

Error creating bean with name 'JobArgs' defined in class path resource [pipelineJob.xml]: 
Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type '$Proxy2 implementing java.io.Serializable,org.springframework.aop.scope.ScopedObject,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised' to required type 'com.test.genepanel.job.JobArguments' for property 'jobArguements'; nested exception is java.lang.IllegalStateException: 
Cannot convert value of type [$Proxy2 implementing java.io.Serializable,org.springframework.aop.scope.ScopedObject,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.test.genepanel.job.JobArguments] for property 'jobArguements': no matching editors or conversion strategy found 

XML包含

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:batch="http://www.springframework.org/schema/batch" 
    xmlns:aop="http://www.springframework.org/schema/aop" 
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:util="http://www.springframework.org/schema/util" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
      http://www.springframework.org/schema/batch 
      http://www.springframework.org/schema/batch/spring-batch-2.1.xsd 
      http://www.springframework.org/schema/aop 
      http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 
      http://www.springframework.org/schema/util 
      http://www.springframework.org/schema/util/spring-util-2.5.xsd"> 

    <batch:job id="pipelineJob"> 
     <batch:step id="initializationStep" next="CleanUPStep"> 
      <batch:tasklet ref="initializationStepTasklet" /> 
     </batch:step> 
     <batch:step id="CleanUPStep"> 
      <batch:tasklet ref="cleanupTaskLet" /> 
     </batch:step> 
    </batch:job> 



    <bean id="basicStep" class="com.test.mutation.steps.BasicStep" abstract="true"> 
     <property name="testJobArgs" ref="JobArgs"/> 
    </bean> 

    <bean id="JobArgs" class="com.test.mutation.application.TestJobArguements"> 
     <property name="jobArguements" ref="jobArg"> 
     </property> 
    </bean> 

    <bean id="jobArg" class="com.test.genepanel.job.JobArguments" scope="step"> 
     <constructor-arg value="#{jobParameters['jobOutputDir']}"/> 
    </bean> 

    <bean id="emptyTaskLet" class="com.test.mutation.steps.EmptyStep" scope="step" parent="basicStep" /> 

    <bean id="cleanupTaskLet" class="com.test.mutation.steps.CleanUpStep" scope="step" parent="basicStep"> 
    </bean> 

    <bean id="initializationStepTasklet" class="com.test.mutation.steps.InitializationStep" scope ="step" parent="basicStep"> 
    </bean> 
</beans> 

我缺少什么: 不过,我运行代码时有以下错误?

+0

是bean的'JobArgs'类名和属性拼写错误? –

+0

@MihaiSoloi:我已经更新了代码,我在发布时更改了一些类名。 – Sach

回答

0

我已经看遍了所有的Spring引用,并且我还没有在构造函数参数中看到后期绑定,所以我不确定它是否有效。我假设你正在设置在JobArgs的jobParameters,在这种情况下,它应该有使用步骤范围相同scope="step"

1

简单的方法是这样的:

<bean id="myReader" class="org.springframework.batch.item.file.FlatFileItemReader" scope="step"> 
    <property name="resource" value="file:#{jobParameters['input.file']}" /> 
    <property name="linesToSkip" value="0" /> 
    <property name="recordSeparatorPolicy" ref="simpleRecordPolicy" /> 
    <property name="lineMapper" ref="journalSicIemtLineMapper" /> 
</bean> 

配售步骤范围的豆会推迟他的创作,直到他提到的即将开始的步骤。这就是Late-binding的意思,所以你可以访问ExecutionContext中的变量。

正如StepScope的文档指出:

豆与StepScope将AOP:作用域代理。这意味着代理绕过真实的对象。

所以当你定义一个普通的Spring Beans(就像你用jobArg做的那样)并且把scope = step放在它上面。当你想在另一个bean中设置它时(JobArgs),你必须找到一种方法来检索这个代理中的对象。

+0

您是否需要在春季环境中的某处启用aop:scope以启用对jobParameter的访问? – emeraldjava

相关问题