2012-04-03 4 views
0

私はスプリング3でアプリケーションを開発しています。私はスプリングバッチでいくつかのテストをしています。これが私の仕事の定義である:テストスプリングバッチは何もしません

job.xml:

バッチのcontext.xml:

<bean id="txManager" 
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> 
    <property name="dataSource" ref="dataSource" /> 
</bean> 

<batch:job-repository id="jobRepository" 
    data-source="dataSource" transaction-manager="txManager" 
    isolation-level-for-create="SERIALIZABLE" table-prefix="BATCH_" 
    max-varchar-length="1000" /> 

<bean id="jobLauncher" 
    class="org.springframework.batch.core.launch.support.SimpleJobLauncher"> 
    <property name="jobRepository" ref="jobRepository" /> 
</bean> 

<bean id="fabio" class="com.firststepteam.handshake.jobs.PrintTasklet"> 
    <property name="message" value="Fabio"/> 
</bean> 

<bean id="taskletStep" abstract="true" 
    class="org.springframework.batch.core.step.tasklet.TaskletStep"> 
    <property name="jobRepository" ref="jobRepository"/> 
    <property name="transactionManager" ref="txManager"/> 
</bean> 

<bean id="simpleJob" class="org.springframework.batch.core.job.SimpleJob"> 
    <property name="name" value="simpleJob" /> 
    <property name="steps"> 
     <list> 
      <bean parent="taskletStep"> 
       <property name="tasklet" ref="fabio"/> 
      </bean> 
     </list> 
    </property> 
    <property name="jobRepository" ref="jobRepository"/> 
</bean> 

これは私がバッチを設定する方法です

実行したいタスクレット:

public class PrintTasklet implements Tasklet{ 

private String message; 

public void setMessage(String message) { 
    this.message = message; 
} 

public ExitStatus execute() throws Exception { 
    System.out.println("Hello "+message); 
    return ExitStatus.COMPLETED; 
} 

これは私がジョブを実行しようとしている方法です:

mvn clean compile exec:java -Dexec.mainClass=org.springframework.batch.core.launch.support.CommandLineJobRunner -Dexec.args="job.xml simpleJob" 

何も起こりません。例外なく。ジョブの実行は正しい方法でデータベースに保存されます。しかし、私のタスクレットは実行されていません。 ここで何が間違っていますか?

私はUbuntu 10.10でmaven 2.2.1を使用しています。春バッチバージョンは2.1.8

+0

ご使用の環境の詳細を追加してください。オペレーティング·システム? Mavenバージョン、特に3.0のバネバッチバージョン+ TaskstartはRepeatstatusで動作し、Exitstatusでは動作しません。https://github.com/langmi/spring-batch-tutorials/blob/master/hello-world-java/srcを参照してください。 /main/java/de/langmi/spring/batch/tutorials/helloworld/HelloWorldTasklet.java –

+0

更新された詳細 – Fabio

答えて

0

問題を解決しました。マイケルランゲが示唆するように、私はちょうどこのようにした:

@Override 
public RepeatStatus execute(StepContribution contribution, 
          ChunkContext chunkContext) throws Exception { 

    // why not using println? because it makes testing harder, *nix and 
    // windows think different about new line as in \n vs \r\n 
    System.out.print("Hello World! "+message); 

    return RepeatStatus.FINISHED; 
} 

そして、うまくいきます。

関連する問題