Тест весенней партии ничего не делать - PullRequest
0 голосов
/ 03 апреля 2012

Я разрабатываю приложение с помощью Spring 3. Я провожу некоторые тесты с помощью Spring Batch. Это мое определение работы:

job.xml:

<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>

Вот как я настраиваю пакет:

партия-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>

Тасклет, который я хочу запустить:

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"

Ничего не происходит. Без исключений. Выполнение задания правильно сохраняется в базе данных. Но мой тасклет не работает. Что я тут не так делаю?

Я использую maven 2.2.1 в Ubuntu 10.10. Версия Spring Batch - 2.1.8

1 Ответ

0 голосов
/ 04 апреля 2012

Проблема решена.Как предполагает Майкл Ланге, я просто сделал так:

@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;
}

И отлично работает.

...