Created
February 2, 2012 16:26
-
-
Save xdu/1724384 to your computer and use it in GitHub Desktop.
spring batch configurations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<beans xmlns="http://www.springframework.org/schema/beans" | |
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:context="http://www.springframework.org/schema/context" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation=" | |
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-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/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd | |
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd "> | |
<bean id="placeholderConfig" | |
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> | |
<property name="location" value="batch.properties" /> | |
</bean> | |
<bean id="dataSource" | |
class="org.apache.commons.dbcp.BasicDataSource" | |
destroy-method="close"> | |
<property name="driverClassName" value="${db.driver}" /> | |
<property name="url" value="${db.url}" /> | |
<property name="username" value="${db.username}" /> | |
<property name="password" value="${db.password}" /> | |
</bean> | |
<bean id="transactionManager" | |
class="org.springframework.jdbc.datasource.DataSourceTransactionManager" | |
lazy-init="true"> | |
<property name="dataSource" ref="dataSource" /> | |
</bean> | |
<bean id="jobRepository" | |
class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean" | |
p:dataSource-ref="dataSource" | |
p:transactionManager-ref="transactionManager" /> | |
<bean id="jobLauncher" | |
class="org.springframework.batch.core.launch.support.SimpleJobLauncher"> | |
<property name="jobRepository" ref="jobRepository" /> | |
</bean> | |
<bean id="incrementer" class="org.springframework.batch.core.launch.support.RunIdIncrementer"/> | |
<bean id="jobExplorer" class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean" | |
p:dataSource-ref="dataSource"/> | |
<bean class="org.springframework.batch.test.JobLauncherTestUtils"/> | |
</beans> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<beans:bean id="idIncrementer" | |
class="org.springframework.batch.core.launch.support.RunIdIncrementer"/> | |
<job id="demoJob" incrementer="idIncrementer"> | |
... | |
</job> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<beans xmlns:batch="http://www.springframework.org/schema/batch" | |
xmlns="http://www.springframework.org/schema/beans" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
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"> | |
<batch:job id="demoJob"> | |
... | |
<listeners> | |
<listener ref="loggingListener"/> | |
</listeners> | |
</batch:job> | |
</beans> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<job id="flowJob"> | |
<step id="retryStep"> | |
<tasklet> | |
<chunk reader="itemReader" writer="itemWriter" | |
processor="itemProcessor" commit-interval="20" retry-limit="3"> | |
<retryable-exception-classes> | |
<include class="org.springframework.remoting.RemoteAccessException"/> | |
</retryable-exception-classes> | |
</chunk> | |
</tasklet> | |
</step> | |
</job> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public RepeatStatus execute(StepContribution step, ChunkContext context) | |
throws Exception { | |
String name = (String) context.getStepContext().getJobParameters().get("name"); | |
System.out.println(name); | |
ExecutionContext jobContext = context.getStepContext() | |
.getStepExecution() | |
.getJobExecution() | |
.getExecutionContext(); | |
jobContext.put(“user.name", name); | |
return RepeatStatus.FINISHED; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ParameterValidator implements JobParametersValidator { | |
public void validate(JobParameters parameters) throws JobParametersInvalidException { | |
String name = parameters.getString("name"); | |
if (!StringUtils.isAlpha(name)) { | |
throw new JobParametersInvalidException("Name is not alphabetic"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment