[pull] main from spring-projects:main#12
Conversation
Before this commit, it was required to populate the job registry with a different component (like a bean post processor or a smart initializing singleton) before being able to use it with the JobOperator. This commit makes the `MapJobRegistry` smart enough to auto register jobs defined in the application context. This removes the need for a distinct component to populate the registry and therefore simplifies the configuration. This commit also: - removes the usage of `JobFactory` from `JobRegistry` - deprecates JobRegistrySmartInitializingSingleton and removes its configuration from the default batch configuration Resolves #4854 Resolves #4855 Resolves #4856
Reviewer's GuideThis PR refactors the job registry to directly manage Job instances with automatic bean discovery and registration, deprecates the legacy JobRegistrySmartInitializingSingleton in favor of the enhanced MapJobRegistry, updates job registration logic across core classes, and adapts tests and configuration to the new API. Sequence Diagram: Automatic Job Registration by MapJobRegistrysequenceDiagram
participant AC as ApplicationContext
participant MJR as MapJobRegistry
AC ->> MJR: setApplicationContext(applicationContext)
AC ->> MJR: afterSingletonsInstantiated()
MJR ->> AC: getBeansOfType(Job.class)
AC -->> MJR: Map<String, Job> jobBeans
MJR ->> MJR: map.putAll(jobBeans)
Class Diagram: Updated Job Registration ComponentsclassDiagram
direction LR
class JobRegistry {
<<Interface>>
+register(Job job)
+unregister(String name)
+getJob(String name) Job
+getJobNames() Set~String~
}
class MapJobRegistry {
+ConcurrentMap~String, Job~ map
+ApplicationContext applicationContext
+Log logger
+setApplicationContext(ApplicationContext context)
+afterSingletonsInstantiated()
+register(Job job)
+unregister(String name)
+getJob(String name) Job
+getJobNames() Set~String~
}
MapJobRegistry --|> JobRegistry
MapJobRegistry ..> ApplicationContext : uses
MapJobRegistry ..> Job : aggregates
class SmartInitializingSingleton {
<<Interface>>
+afterSingletonsInstantiated()
}
MapJobRegistry --|> SmartInitializingSingleton
class ApplicationContextAware {
<<Interface>>
+setApplicationContext(ApplicationContext context)
}
MapJobRegistry --|> ApplicationContextAware
class JobRegistrySmartInitializingSingleton {
<<Deprecated>>
-JobRegistry jobRegistry
-BeanFactory beanFactory
-Set~String~ jobNames
+setJobRegistry(JobRegistry jobRegistry)
+setBeanFactory(BeanFactory beanFactory)
+afterPropertiesSet()
+destroy()
+afterSingletonsInstantiated()
#postProcessAfterInitialization(Job job, String beanName)
}
JobRegistrySmartInitializingSingleton o-- JobRegistry
class Job {
<<Interface>>
+getName() String
}
class DefaultJobLoader {
-JobRegistry jobRegistry
#doRegister(ConfigurableApplicationContext context, Job job)
}
DefaultJobLoader o-- JobRegistry
class JobFactoryRegistrationListener {
-JobRegistry jobRegistry
+bind(JobFactory jobFactory, Map params)
}
JobFactoryRegistrationListener o-- JobRegistry
class JobFactory {
<<Interface>>
+createJob() Job
+getJobName() String
}
JobFactoryRegistrationListener ..> JobFactory : uses
class DefaultBatchConfiguration {
+jobLauncher(JobRepository jr) JobLauncher
+jobRepository(DataSource ds, PlatformTransactionManager tm) JobRepository
+jobRegistry() JobRegistry
+jobOperator(JobRepository jr, JobRegistry jreg, JobLauncher jl, JobExplorer je, PlatformTransactionManager tm) JobOperator
}
DefaultBatchConfiguration ..> JobRegistry : creates
class BatchRegistrar {
+registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry)
}
BatchRegistrar ..> BeanDefinitionRegistry : uses
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Join our Discord community for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
See Commits and Changes for more details.
Created by
pull[bot] (v2.0.0-alpha.1)
Can you help keep this open source service alive? 💖 Please sponsor : )
Summary by Sourcery
Enhance the JobRegistry implementation by auto-populating MapJobRegistry with Job beans and streamline the API to register Job instances directly while deprecating the old JobFactory-based initializer and cleaning up related configuration and tests.
New Features:
Enhancements:
Tests: