2013-07-09 91 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

相關問題