public class SpringBeanJobFactory extends AdaptableJobFactory implements ApplicationContextAware, SchedulerContextAware
AdaptableJobFactory
that also supports Spring-style
dependency injection on bean properties. This is essentially the direct
equivalent of Spring's QuartzJobBean
in the shape of a Quartz
JobFactory
.
Applies scheduler context, job data map and trigger data map entries as bean property values. If no matching bean property is found, the entry is by default simply ignored. This is analogous to QuartzJobBean's behavior.
Compatible with Quartz 2.1.4 and higher, as of Spring 4.1.
SchedulerFactoryBean.setJobFactory(org.quartz.spi.JobFactory)
,
QuartzJobBean
Constructor and Description |
---|
SpringBeanJobFactory() |
Modifier and Type | Method and Description |
---|---|
protected java.lang.Object |
createJobInstance(TriggerFiredBundle bundle)
Create the job instance, populating it with property values taken
from the scheduler context, job data map and trigger data map.
|
protected boolean |
isEligibleForPropertyPopulation(java.lang.Object jobObject)
Return whether the given job object is eligible for having
its bean properties populated.
|
void |
setApplicationContext(ApplicationContext applicationContext)
Set the ApplicationContext that this object runs in.
|
void |
setIgnoredUnknownProperties(java.lang.String... ignoredUnknownProperties)
Specify the unknown properties (not found in the bean) that should be ignored.
|
void |
setSchedulerContext(SchedulerContext schedulerContext)
Set the SchedulerContext of the current Quartz Scheduler.
|
adaptJob, newJob
public void setIgnoredUnknownProperties(java.lang.String... ignoredUnknownProperties)
Default is null
, indicating that all unknown properties
should be ignored. Specify an empty array to throw an exception in case
of any unknown properties, or a list of property names that should be
ignored if there is no corresponding property found on the particular
job class (all other unknown properties will still trigger an exception).
public void setApplicationContext(ApplicationContext applicationContext)
ApplicationContextAware
Invoked after population of normal bean properties but before an init callback such
as InitializingBean.afterPropertiesSet()
or a custom init-method. Invoked after ResourceLoaderAware.setResourceLoader(org.springframework.core.io.ResourceLoader)
,
ApplicationEventPublisherAware.setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher)
and
MessageSourceAware
, if applicable.
setApplicationContext
in interface ApplicationContextAware
applicationContext
- the ApplicationContext object to be used by this objectBeanInitializationException
public void setSchedulerContext(SchedulerContext schedulerContext)
SchedulerContextAware
setSchedulerContext
in interface SchedulerContextAware
Scheduler.getContext()
protected java.lang.Object createJobInstance(TriggerFiredBundle bundle) throws java.lang.Exception
createJobInstance
in class AdaptableJobFactory
bundle
- the TriggerFiredBundle from which the JobDetail
and other info relating to the trigger firing can be obtainedjava.lang.Exception
- if job instantiation failedprotected boolean isEligibleForPropertyPopulation(java.lang.Object jobObject)
The default implementation ignores QuartzJobBean
instances,
which will inject bean properties themselves.
jobObject
- the job object to introspectQuartzJobBean