Class DefaultBatchConfiguration
java.lang.Object
org.springframework.batch.core.configuration.support.DefaultBatchConfiguration
- All Implemented Interfaces:
org.springframework.beans.factory.Aware
,org.springframework.context.ApplicationContextAware
@Configuration(proxyBeanMethods=false)
@Import(ScopeConfiguration.class)
public class DefaultBatchConfiguration
extends Object
implements org.springframework.context.ApplicationContextAware
Base
Configuration
class that provides common JDBC-based infrastructure beans
for enabling and using Spring Batch.
This configuration class configures and registers the following beans in the application context:
- a
JobRepository
named "jobRepository" - a
JobExplorer
named "jobExplorer" - a
JobLauncher
named "jobLauncher" - a
JobRegistry
named "jobRegistry" - a
JobOperator
named "JobOperator" - a
JobRegistryBeanPostProcessor
named "jobRegistryBeanPostProcessor" - a
StepScope
named "stepScope" - a
JobScope
named "jobScope"
A typical usage of this class is as follows:
@Configuration public class MyJobConfiguration extends DefaultBatchConfiguration { @Bean public Job job(JobRepository jobRepository) { return new JobBuilder("myJob", jobRepository) // define job flow as needed .build(); } }
- Since:
- 5.0
- Author:
- Dave Syer, Michael Minella, Mahmoud Ben Hassine, Taeik Lim
-
Field Summary
Modifier and TypeFieldDescriptionprotected org.springframework.context.ApplicationContext
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected Charset
Return theCharset
to use when serializing/deserializing the execution context.protected int
Return the value fromTypes
class to indicate the type to use for a CLOBprotected org.springframework.core.convert.support.ConfigurableConversionService
Return the conversion service to use in the job repository and job explorer.protected String
Return the database type.protected DataSource
Return the data source to use for Batch meta-data.protected ExecutionContextSerializer
A custom implementation of theExecutionContextSerializer
.protected DataFieldMaxValueIncrementerFactory
Return the factory for creatingDataFieldMaxValueIncrementer
implementations used to increment entity IDs in meta-data tables.protected org.springframework.transaction.annotation.Isolation
Return the transaction isolation level when creating job executions.protected org.springframework.jdbc.core.JdbcOperations
Return theJdbcOperations
.protected JobKeyGenerator
A custom implementation of theJobKeyGenerator
.protected org.springframework.jdbc.support.lob.LobHandler
A special handler for large objects.protected int
Return the length of long string columns in database.protected String
Return the prefix of Batch meta-data tables.protected org.springframework.core.task.TaskExecutor
Return theTaskExecutor
to use in the the job launcher.protected org.springframework.transaction.PlatformTransactionManager
Return the transaction manager to use for the job repository.protected boolean
Return the value of thevalidateTransactionState
parameter.Deprecated, for removal: This API element is subject to removal in a future version.Since 5.2.jobLauncher
(JobRepository jobRepository) Define a job launcher bean.Deprecated, for removal: This API element is subject to removal in a future version.Since 5.2.jobOperator
(JobRepository jobRepository, JobExplorer jobExplorer, JobRegistry jobRegistry, JobLauncher jobLauncher) Define a job operator bean.Deprecated, for removal: This API element is subject to removal in a future version.jobRegistrySmartInitializingSingleton
(JobRegistry jobRegistry) Define aJobRegistrySmartInitializingSingleton
bean.void
setApplicationContext
(org.springframework.context.ApplicationContext applicationContext)
-
Field Details
-
applicationContext
protected org.springframework.context.ApplicationContext applicationContext
-
-
Constructor Details
-
DefaultBatchConfiguration
public DefaultBatchConfiguration()
-
-
Method Details
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException - Specified by:
setApplicationContext
in interfaceorg.springframework.context.ApplicationContextAware
- Throws:
org.springframework.beans.BeansException
-
jobRepository
- Throws:
BatchConfigurationException
-
jobLauncher
Deprecated, for removal: This API element is subject to removal in a future version.Since 5.2. UsejobLauncher(JobRepository)
insteadDefine a job launcher.- Returns:
- a job launcher
- Throws:
BatchConfigurationException
- if unable to configure the default job launcher
-
jobLauncher
@Bean public JobLauncher jobLauncher(JobRepository jobRepository) throws BatchConfigurationException Define a job launcher bean.- Parameters:
jobRepository
- the job repository- Returns:
- a job launcher
- Throws:
BatchConfigurationException
- if unable to configure the default job launcher- Since:
- 5.2
-
jobExplorer
- Throws:
BatchConfigurationException
-
jobRegistry
- Throws:
BatchConfigurationException
-
jobOperator
Deprecated, for removal: This API element is subject to removal in a future version.Since 5.2. UsejobOperator(JobRepository, JobExplorer, JobRegistry, JobLauncher)
insteadDefine a job operator.- Returns:
- a job operator
- Throws:
BatchConfigurationException
- if unable to configure the default job operator
-
jobOperator
@Bean public JobOperator jobOperator(JobRepository jobRepository, JobExplorer jobExplorer, JobRegistry jobRegistry, JobLauncher jobLauncher) throws BatchConfigurationException Define a job operator bean.- Parameters:
jobRepository
- a job repositoryjobExplorer
- a job explorerjobRegistry
- a job registryjobLauncher
- a job launcher- Returns:
- a job operator
- Throws:
BatchConfigurationException
- if unable to configure the default job operator- Since:
- 5.2
-
jobRegistryBeanPostProcessor
@Deprecated(forRemoval=true) public JobRegistryBeanPostProcessor jobRegistryBeanPostProcessor() throws BatchConfigurationExceptionDeprecated, for removal: This API element is subject to removal in a future version.Defines aJobRegistryBeanPostProcessor
.- Returns:
- a
JobRegistryBeanPostProcessor
- Throws:
BatchConfigurationException
- if unable to register the bean- Since:
- 5.1
-
jobRegistrySmartInitializingSingleton
@Bean public JobRegistrySmartInitializingSingleton jobRegistrySmartInitializingSingleton(JobRegistry jobRegistry) throws BatchConfigurationException Define aJobRegistrySmartInitializingSingleton
bean.- Parameters:
jobRegistry
- the job registry to populate- Returns:
- a bean of type
JobRegistrySmartInitializingSingleton
- Throws:
BatchConfigurationException
- if unable to register the bean- Since:
- 5.2
-
getDataSource
Return the data source to use for Batch meta-data. Defaults to the bean of typeDataSource
and named "dataSource" in the application context.- Returns:
- The data source to use for Batch meta-data
-
getTransactionManager
protected org.springframework.transaction.PlatformTransactionManager getTransactionManager()Return the transaction manager to use for the job repository. Defaults to the bean of typePlatformTransactionManager
and named "transactionManager" in the application context.- Returns:
- The transaction manager to use for the job repository
-
getValidateTransactionState
protected boolean getValidateTransactionState()Return the value of thevalidateTransactionState
parameter. Defaults totrue
.- Returns:
- true if the transaction state should be validated, false otherwise
-
getIsolationLevelForCreate
protected org.springframework.transaction.annotation.Isolation getIsolationLevelForCreate()Return the transaction isolation level when creating job executions. Defaults toIsolation.SERIALIZABLE
.- Returns:
- the transaction isolation level when creating job executions
-
getMaxVarCharLength
protected int getMaxVarCharLength()Return the length of long string columns in database. Do not override this if you haven't modified the schema. Note this value will be used for the exit message in bothJdbcJobExecutionDao
andJdbcStepExecutionDao
and also the short version of the execution context inJdbcExecutionContextDao
. For databases with multi-byte character sets this number can be smaller (by up to a factor of 2 for 2-byte characters) than the declaration of the column length in the DDL for the tables. Defaults toAbstractJdbcBatchMetadataDao.DEFAULT_EXIT_MESSAGE_LENGTH
-
getTablePrefix
Return the prefix of Batch meta-data tables. Defaults toAbstractJdbcBatchMetadataDao.DEFAULT_TABLE_PREFIX
.- Returns:
- the prefix of meta-data tables
-
getCharset
Return theCharset
to use when serializing/deserializing the execution context. Defaults to "UTF-8".- Returns:
- the charset to use when serializing/deserializing the execution context
-
getLobHandler
protected org.springframework.jdbc.support.lob.LobHandler getLobHandler()A special handler for large objects. The default is usually fine, except for some (usually older) versions of Oracle.- Returns:
- the
LobHandler
to use
-
getJdbcOperations
protected org.springframework.jdbc.core.JdbcOperations getJdbcOperations()Return theJdbcOperations
. If this property is not overridden, a newJdbcTemplate
will be created for the configured data source by default.- Returns:
- the
JdbcOperations
to use
-
getExecutionContextSerializer
A custom implementation of theExecutionContextSerializer
. The default, if not injected, is theDefaultExecutionContextSerializer
.- Returns:
- the serializer to use to serialize/deserialize the execution context
-
getClobType
protected int getClobType()Return the value fromTypes
class to indicate the type to use for a CLOB- Returns:
- the value from
Types
class to indicate the type to use for a CLOB
-
getIncrementerFactory
Return the factory for creatingDataFieldMaxValueIncrementer
implementations used to increment entity IDs in meta-data tables.- Returns:
- the factory for creating
DataFieldMaxValueIncrementer
implementations.
-
getJobKeyGenerator
A custom implementation of theJobKeyGenerator
. The default, if not injected, is theDefaultJobKeyGenerator
.- Returns:
- the generator that creates the key used in identifying
JobInstance
objects - Since:
- 5.1
-
getDatabaseType
Return the database type. The default will be introspected from the JDBC meta-data of the data source.- Returns:
- the database type
- Throws:
org.springframework.jdbc.support.MetaDataAccessException
- if an error occurs when trying to get the database type of JDBC meta-data
-
getTaskExecutor
protected org.springframework.core.task.TaskExecutor getTaskExecutor()Return theTaskExecutor
to use in the the job launcher. Defaults toSyncTaskExecutor
.- Returns:
- the
TaskExecutor
to use in the the job launcher.
-
getConversionService
protected org.springframework.core.convert.support.ConfigurableConversionService getConversionService()Return the conversion service to use in the job repository and job explorer. This service is used to convert job parameters from String literal to typed values and vice versa.- Returns:
- the
ConfigurableConversionService
to use.
-