Class JobRegistrySmartInitializingSingleton
java.lang.Object
org.springframework.batch.core.configuration.support.JobRegistrySmartInitializingSingleton
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanFactoryAware,org.springframework.beans.factory.DisposableBean,org.springframework.beans.factory.InitializingBean,org.springframework.beans.factory.SmartInitializingSingleton
public class JobRegistrySmartInitializingSingleton
extends Object
implements org.springframework.beans.factory.SmartInitializingSingleton, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean
A
SmartInitializingSingleton that registers Job beans with a
JobRegistry. Include a bean of this type along with your job configuration and
use the same JobRegistry as a JobLocator when you need to locate a
Job to launch.
This class is an alternative to JobRegistryBeanPostProcessor and prevents early
bean initializations. You must include at most one of either of them as a bean.
- Since:
- 5.1.1
- Author:
- Henning Pƶttker
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.JobRegistrySmartInitializingSingleton(JobRegistry jobRegistry) Convenience constructor for setting theJobRegistry. -
Method Summary
Modifier and TypeMethodDescriptionvoidMake sure the registry is set before use.voidvoiddestroy()Unregister all theJobinstances that were registered by this smart initializing singleton.protected StringgetGroupName(org.springframework.beans.factory.config.BeanDefinition beanDefinition, Job job) Determine a group name for the job to be registered.voidsetBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) voidsetGroupName(String groupName) The group name for jobs registered by this component.voidsetJobRegistry(JobRegistry jobRegistry) Injection setter forJobRegistry.
-
Constructor Details
-
JobRegistrySmartInitializingSingleton
public JobRegistrySmartInitializingSingleton()Default constructor. -
JobRegistrySmartInitializingSingleton
Convenience constructor for setting theJobRegistry.- Parameters:
jobRegistry- theJobRegistryto register theJobs with
-
-
Method Details
-
setGroupName
The group name for jobs registered by this component. Optional (defaults to null, which means that jobs are registered with their bean names). Useful where there is a hierarchy of application contexts all contributing to the sameJobRegistry: child contexts can then define an instance with a unique group name to avoid clashes between job names.- Parameters:
groupName- the groupName to set
-
setJobRegistry
Injection setter forJobRegistry.- Parameters:
jobRegistry- theJobRegistryto register theJobs with
-
setBeanFactory
public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) throws org.springframework.beans.BeansException - Specified by:
setBeanFactoryin interfaceorg.springframework.beans.factory.BeanFactoryAware- Throws:
org.springframework.beans.BeansException
-
afterPropertiesSet
Make sure the registry is set before use.- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
Exception
-
destroy
Unregister all theJobinstances that were registered by this smart initializing singleton.- Specified by:
destroyin interfaceorg.springframework.beans.factory.DisposableBean- Throws:
Exception
-
afterSingletonsInstantiated
public void afterSingletonsInstantiated()- Specified by:
afterSingletonsInstantiatedin interfaceorg.springframework.beans.factory.SmartInitializingSingleton
-
getGroupName
protected String getGroupName(org.springframework.beans.factory.config.BeanDefinition beanDefinition, Job job) Determine a group name for the job to be registered. The default implementation returns thegroupNameconfigured. Provides an extension point for specialised subclasses.- Parameters:
beanDefinition- the bean definition for the jobjob- the job- Returns:
- a group name for the job (or null if not needed)
-