Top Description Inners Fields Constructors Methods
org.springframework.scheduling.quartz

public Class MethodInvokingJobDetailFactoryBean

extends ArgumentConvertingMethodInvoker
implements org.springframework.beans.factory.FactoryBean<org.quartz.JobDetail>, BeanNameAware, BeanClassLoaderAware, BeanFactoryAware, InitializingBean
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.FactoryBean
Imports
java.lang.reflect.InvocationTargetException, org.apache.commons.logging.Log, .LogFactory, org.quartz.DisallowConcurrentExecution, org.quartz.Job, org.quartz.JobDetail, org.quartz.JobExecutionContext, org.quartz.JobExecutionException, org.quartz.PersistJobDataAfterExecution, org.quartz.Scheduler, org.quartz.impl.JobDetailImpl, org.springframework.beans.factory.BeanClassLoaderAware, .BeanFactory, .BeanFactoryAware, .BeanNameAware, .FactoryBean, .InitializingBean, org.springframework.beans.support.ArgumentConvertingMethodInvoker, org.springframework.lang.Nullable, org.springframework.util.Assert, .ClassUtils, .MethodInvoker

org.springframework.beans.factory.FactoryBean that exposes a org.quartz.JobDetail object which delegates job execution to a specified (static or non-static) method. Avoids the need for implementing a one-line Quartz Job that just invokes an existing service method on a Spring-managed target bean.

Inherits common configuration properties from the MethodInvoker base class, such as "targetObject" and "targetMethod", adding support for lookup of the target bean by name through the "targetBeanName" property (as alternative to specifying a "targetObject" directly, allowing for non-singleton target objects).

Supports both concurrently running jobs and non-currently running jobs through the "concurrent" property. Jobs created by this MethodInvokingJobDetailFactoryBean are by default volatile and durable (according to Quartz terminology).

NOTE: JobDetails created via this FactoryBean are not serializable and thus not suitable for persistent job stores. You need to implement your own Quartz Job as a thin wrapper for each case where you want a persistent job to delegate to a specific service method.

Compatible with Quartz 2.1.4 and higher, as of Spring 4.1.

Authors
Juergen Hoeller, Alef Arendsen
Since
18.02.2004
See Also
setTargetBeanName, setTargetObject, setTargetMethod, setConcurrent

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
MethodInvokingJobDetailFactoryBean.MethodInvokingJob

Quartz Job implementation that invokes a specified method.

public static class
MethodInvokingJobDetailFactoryBean.StatefulMethodInvokingJob

Extension of the MethodInvokingJob, implementing the StatefulJob interface.

Field Summary

Modifier and TypeField and Description
private ClassLoader
private BeanFactory
private String
private boolean
private String
private org.quartz.JobDetail
private String
private String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
afterPropertiesSet()

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Invoked by the containing BeanFactory after it has set all bean properties and satisfied BeanFactoryAware, ApplicationContextAware etc.

This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.

public org.quartz.JobDetail
getObject()

Implements org.springframework.beans.factory.FactoryBean.getObject.

Return an instance (possibly shared or independent) of the object managed by this factory.

public Class<? extends org.quartz.JobDetail>
getObjectType()

Implements org.springframework.beans.factory.FactoryBean.getObjectType.

Return the type of object that this FactoryBean creates, or null if not known in advance.

public Class<?>
public Object
public boolean
isSingleton()

Overrides default org.springframework.beans.factory.FactoryBean.isSingleton.

Is the object managed by this factory a singleton?

protected void
postProcessJobDetail(org.quartz.JobDetail
the JobDetail prepared by this FactoryBean
jobDetail
)

Callback for post-processing the JobDetail to be exposed by this FactoryBean.

protected Class<?>
resolveClassName(String
the class name to resolve
className
)

Overrides org.springframework.util.MethodInvoker.resolveClassName.

Resolve the given class name into a Class.

public void
setBeanClassLoader(ClassLoader
the owning class loader
classLoader
)

Implements org.springframework.beans.factory.BeanClassLoaderAware.setBeanClassLoader.

Callback that supplies the bean class loader to a bean instance.

public void
setBeanFactory(BeanFactory
owning BeanFactory (never null). The bean can immediately call methods on the factory.
beanFactory
)

Implements org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

Callback that supplies the owning factory to a bean instance.

public void
setBeanName(String
the name of the bean in the factory. Note that this name is the actual bean name used in the factory, which may differ from the originally specified name: in particular for inner bean names, the actual bean name might have been made unique through appending "#..." suffixes. Use the BeanFactoryUtils#originalBeanName(String) method to extract the original bean name (without suffix), if desired.
beanName
)

Implements org.springframework.beans.factory.BeanNameAware.setBeanName.

Set the name of the bean in the bean factory that created this bean.

public void
setConcurrent(boolean concurrent)

Specify whether multiple jobs should be run in a concurrent fashion.

public void
setGroup(String group)

Set the group of the job.

public void
setName(String name)

Set the name of the job.

public void
setTargetBeanName(String targetBeanName)

Set the name of the target bean in the Spring BeanFactory.

Inherited from org.springframework.beans.support.ArgumentConvertingMethodInvoker:
doFindMatchingMethodfindMatchingMethodgetDefaultTypeConvertergetTypeConverterregisterCustomEditorsetTypeConverter

Field Detail

beanClassLoaderback to summary
private ClassLoader beanClassLoader
Annotations
@Nullable
beanFactoryback to summary
private BeanFactory beanFactory
Annotations
@Nullable
beanNameback to summary
private String beanName
Annotations
@Nullable
concurrentback to summary
private boolean concurrent
groupback to summary
private String group
jobDetailback to summary
private org.quartz.JobDetail jobDetail
Annotations
@Nullable
nameback to summary
private String name
Annotations
@Nullable
targetBeanNameback to summary
private String targetBeanName
Annotations
@Nullable

Constructor Detail

MethodInvokingJobDetailFactoryBeanback to summary
public MethodInvokingJobDetailFactoryBean()

Method Detail

afterPropertiesSetback to summary
public void afterPropertiesSet() throws ClassNotFoundException, NoSuchMethodException

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Doc from org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Invoked by the containing BeanFactory after it has set all bean properties and satisfied BeanFactoryAware, ApplicationContextAware etc.

This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.

Annotations
@Override
getObjectback to summary
public org.quartz.JobDetail getObject()

Implements org.springframework.beans.factory.FactoryBean.getObject.

Doc from org.springframework.beans.factory.FactoryBean.getObject.

Return an instance (possibly shared or independent) of the object managed by this factory.

As with a BeanFactory, this allows support for both the Singleton and Prototype design pattern.

If this FactoryBean is not fully initialized yet at the time of the call (for example because it is involved in a circular reference), throw a corresponding FactoryBeanNotInitializedException.

As of Spring 2.0, FactoryBeans are allowed to return null objects. The factory will consider this as normal value to be used; it will not throw a FactoryBeanNotInitializedException in this case anymore. FactoryBean implementations are encouraged to throw FactoryBeanNotInitializedException themselves now, as appropriate.

Returns:org.quartz.JobDetail

an instance of the bean (can be null)

Annotations
@Override
@Nullable
getObjectTypeback to summary
public Class<? extends org.quartz.JobDetail> getObjectType()

Implements org.springframework.beans.factory.FactoryBean.getObjectType.

Doc from org.springframework.beans.factory.FactoryBean.getObjectType.

Return the type of object that this FactoryBean creates, or null if not known in advance.

This allows one to check for specific types of beans without instantiating objects, for example on autowiring.

In the case of implementations that are creating a singleton object, this method should try to avoid singleton creation as far as possible; it should rather estimate the type in advance. For prototypes, returning a meaningful type here is advisable too.

This method can be called before this FactoryBean has been fully initialized. It must not rely on state created during initialization; of course, it can still use such state if available.

Note

Autowiring will simply ignore FactoryBeans that return null here. Therefore, it is highly recommended to implement this method properly, using the current state of the FactoryBean.

Returns:Class<? extends org.quartz.JobDetail>

the type of object that this FactoryBean creates, or null if not known at the time of the call

Annotations
@Override
getTargetClassback to summary
public Class<?> getTargetClass()

Overrides org.springframework.util.MethodInvoker.getTargetClass.

Overridden to support the "targetBeanName" feature.

Annotations
@Override
getTargetObjectback to summary
public Object getTargetObject()

Overrides org.springframework.util.MethodInvoker.getTargetObject.

Overridden to support the "targetBeanName" feature.

Annotations
@Override
isSingletonback to summary
public boolean isSingleton()

Overrides default org.springframework.beans.factory.FactoryBean.isSingleton.

Doc from org.springframework.beans.factory.FactoryBean.isSingleton.

Is the object managed by this factory a singleton? That is, will getObject() always return the same object (a reference that can be cached)?

Note

If a FactoryBean indicates to hold a singleton object, the object returned from getObject() might get cached by the owning BeanFactory. Hence, do not return true unless the FactoryBean always exposes the same reference.

The singleton status of the FactoryBean itself will generally be provided by the owning BeanFactory; usually, it has to be defined as singleton there.

Note

This method returning false does not necessarily indicate that returned objects are independent instances. An implementation of the extended SmartFactoryBean interface may explicitly indicate independent instances through its SmartFactoryBean#isPrototype() method. Plain FactoryBean implementations which do not implement this extended interface are simply assumed to always return independent instances if the isSingleton() implementation returns false.

The default implementation returns true, since a FactoryBean typically manages a singleton instance.

Returns:boolean

whether the exposed object is a singleton

Annotations
@Override
postProcessJobDetailback to summary
protected void postProcessJobDetail(org.quartz.JobDetail jobDetail)

Callback for post-processing the JobDetail to be exposed by this FactoryBean.

The default implementation is empty. Can be overridden in subclasses.

Parameters
jobDetail:org.quartz.JobDetail

the JobDetail prepared by this FactoryBean

resolveClassNameback to summary
protected Class<?> resolveClassName(String className) throws ClassNotFoundException

Overrides org.springframework.util.MethodInvoker.resolveClassName.

Doc from org.springframework.util.MethodInvoker.resolveClassName.

Resolve the given class name into a Class.

The default implementations uses ClassUtils.forName, using the thread context class loader.

Parameters
className:String

the class name to resolve

Returns:Class<?>

the resolved Class

Annotations
@Override
Exceptions
ClassNotFoundException:
if the class name was invalid
setBeanClassLoaderback to summary
public void setBeanClassLoader(ClassLoader classLoader)

Implements org.springframework.beans.factory.BeanClassLoaderAware.setBeanClassLoader.

Doc from org.springframework.beans.factory.BeanClassLoaderAware.setBeanClassLoader.

Callback that supplies the bean class loader to a bean instance.

Invoked after the population of normal bean properties but before an initialization callback such as InitializingBean's InitializingBean#afterPropertiesSet() method or a custom init-method.

Parameters
classLoader:ClassLoader

the owning class loader

Annotations
@Override
setBeanFactoryback to summary
public void setBeanFactory(BeanFactory beanFactory)

Implements org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

Doc from org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

Callback that supplies the owning factory to a bean instance.

Invoked after the population of normal bean properties but before an initialization callback such as InitializingBean#afterPropertiesSet() or a custom init-method.

Parameters
beanFactory:BeanFactory

owning BeanFactory (never null). The bean can immediately call methods on the factory.

Annotations
@Override
setBeanNameback to summary
public void setBeanName(String beanName)

Implements org.springframework.beans.factory.BeanNameAware.setBeanName.

Doc from org.springframework.beans.factory.BeanNameAware.setBeanName.

Set the name of the bean in the bean factory that created this bean.

Invoked after population of normal bean properties but before an init callback such as InitializingBean#afterPropertiesSet() or a custom init-method.

Parameters
beanName:String

the name of the bean in the factory. Note that this name is the actual bean name used in the factory, which may differ from the originally specified name: in particular for inner bean names, the actual bean name might have been made unique through appending "#..." suffixes. Use the BeanFactoryUtils#originalBeanName(String) method to extract the original bean name (without suffix), if desired.

Annotations
@Override
setConcurrentback to summary
public void setConcurrent(boolean concurrent)

Specify whether multiple jobs should be run in a concurrent fashion. The behavior when one does not want concurrent jobs to be executed is realized through adding the @PersistJobDataAfterExecution and @DisallowConcurrentExecution markers. More information on stateful versus stateless jobs can be found here.

The default setting is to run jobs concurrently.

setGroupback to summary
public void setGroup(String group)

Set the group of the job.

Default is the default group of the Scheduler.

See Also
org.quartz.Scheduler#DEFAULT_GROUP
setNameback to summary
public void setName(String name)

Set the name of the job.

Default is the bean name of this FactoryBean.

setTargetBeanNameback to summary
public void setTargetBeanName(String targetBeanName)

Set the name of the target bean in the Spring BeanFactory.

This is an alternative to specifying "targetObject", allowing for non-singleton beans to be invoked. Note that specified "targetObject" and "targetClass" values will override the corresponding effect of this "targetBeanName" setting (i.e. statically pre-define the bean type or even the bean object).

org.springframework.scheduling.quartz back to summary

public Class MethodInvokingJobDetailFactoryBean.MethodInvokingJob

extends QuartzJobBean
Class Inheritance
Known Direct Subclasses
org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean.StatefulMethodInvokingJob

Quartz Job implementation that invokes a specified method. Automatically applied by MethodInvokingJobDetailFactoryBean.

Field Summary

Modifier and TypeField and Description
protected static final Log
private MethodInvoker

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
executeInternal(org.quartz.JobExecutionContext context)

Implements abstract org.springframework.scheduling.quartz.QuartzJobBean.executeInternal.

Invoke the method via the MethodInvoker.

public void
setMethodInvoker(MethodInvoker methodInvoker)

Set the MethodInvoker to use.

Inherited from org.springframework.scheduling.quartz.QuartzJobBean:
execute

Field Detail

loggerback to summary
protected static final Log logger
methodInvokerback to summary
private MethodInvoker methodInvoker
Annotations
@Nullable

Constructor Detail

MethodInvokingJobback to summary
public MethodInvokingJob()

Method Detail

executeInternalback to summary
protected void executeInternal(org.quartz.JobExecutionContext context) throws org.quartz.JobExecutionException

Implements abstract org.springframework.scheduling.quartz.QuartzJobBean.executeInternal.

Invoke the method via the MethodInvoker.

Annotations
@Override
setMethodInvokerback to summary
public void setMethodInvoker(MethodInvoker methodInvoker)

Set the MethodInvoker to use.

org.springframework.scheduling.quartz back to summary

public Class MethodInvokingJobDetailFactoryBean.StatefulMethodInvokingJob

extends MethodInvokingJob
Class Inheritance
Annotations
@org.quartz.PersistJobDataAfterExecution
@org.quartz.DisallowConcurrentExecution

Extension of the MethodInvokingJob, implementing the StatefulJob interface. Quartz checks whether jobs are stateful and if so, won't let jobs interfere with each other.

Field Summary

Inherited from org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean.MethodInvokingJob:
logger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Inherited from org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean.MethodInvokingJob:
executeInternalsetMethodInvoker

Constructor Detail

StatefulMethodInvokingJobback to summary
public StatefulMethodInvokingJob()