org.springframework.batch.core.configuration.support

## Class AutomaticJobRegistrar

- java.lang.Object
- - org.springframework.batch.core.configuration.support.AutomaticJobRegistrar

- All Implemented Interfaces:
    java.util.EventListener, org.springframework.beans.factory.Aware, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware, org.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>, org.springframework.context.Lifecycle, org.springframework.core.Ordered

      public class AutomaticJobRegistrar
      extends java.lang.Object
      implements org.springframework.core.Ordered, org.springframework.context.Lifecycle, org.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>, org.springframework.context.ApplicationContextAware, org.springframework.beans.factory.InitializingBean

  Loads and unloads `Jobs` when the application context is created and destroyed. Each resource provided is loaded as an application context with the current context as its parent, and then all the jobs from the child context are registered under their bean names. A `JobRegistry` is required.
  Since:
    2.1
  Author:
    Lucas Ward, Dave Syer

- - ### Field Summary

    - ### Fields inherited from interface org.springframework.core.Ordered

      `HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AutomaticJobRegistrar()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addApplicationContextFactory(ApplicationContextFactory applicationContextFactory)` Add some factories to the set that will be used to load contexts and jobs.
    `void` | `afterPropertiesSet()`
    `int` | `getOrder()`
    `boolean` | `isRunning()` Check if this component has been started.
    `void` | `onApplicationEvent(org.springframework.context.ApplicationEvent event)` Creates all the application contexts required and set up job registry entries with all the instances of `Job` found therein.
    `void` | `setApplicationContext(org.springframework.context.ApplicationContext applicationContext)` The enclosing application context, which can be used to check if `events` come from the expected source.
    `void` | `setApplicationContextFactories(ApplicationContextFactory[] applicationContextFactories)` Add some factories to the set that will be used to load contexts and jobs.
    `void` | `setJobLoader(JobLoader jobLoader)` The job loader that will be used to load and manage jobs.
    `void` | `setOrder(int order)` The order to start up and shutdown.
    `void` | `start()` Take all the contexts from the factories provided and pass them to the `JobLoader`.
    `void` | `stop()` Delegates to `JobLoader.clear()`.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### AutomaticJobRegistrar

          public AutomaticJobRegistrar()

  - ### Method Detail

    - #### setApplicationContext

          public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)

      The enclosing application context, which can be used to check if `events` come from the expected source.
      Specified by:
        `setApplicationContext` in interface `org.springframework.context.ApplicationContextAware`
      Parameters:
        `applicationContext` - the enclosing application context if there is one
      See Also:
        `ApplicationContextAware.setApplicationContext(ApplicationContext)`

    - #### addApplicationContextFactory

          public void addApplicationContextFactory(ApplicationContextFactory applicationContextFactory)

      Add some factories to the set that will be used to load contexts and jobs.
      Parameters:
        `applicationContextFactory` - the `ApplicationContextFactory` values to use

    - #### setApplicationContextFactories

          public void setApplicationContextFactories(ApplicationContextFactory[] applicationContextFactories)

      Add some factories to the set that will be used to load contexts and jobs.
      Parameters:
        `applicationContextFactories` - the `ApplicationContextFactory` values to use

    - #### setJobLoader

          public void setJobLoader(JobLoader jobLoader)

      The job loader that will be used to load and manage jobs.
      Parameters:
        `jobLoader` - the `JobLoader` to set

    - #### getOrder

          public int getOrder()

      Specified by:
        `getOrder` in interface `org.springframework.core.Ordered`

    - #### setOrder

          public void setOrder(int order)

      The order to start up and shutdown.
      Parameters:
        `order` - the order (default `Ordered.LOWEST_PRECEDENCE`).
      See Also:
        `Ordered`

    - #### afterPropertiesSet

          public void afterPropertiesSet()

      Specified by:
        `afterPropertiesSet` in interface `org.springframework.beans.factory.InitializingBean`

    - #### onApplicationEvent

          public final void onApplicationEvent(org.springframework.context.ApplicationEvent event)

      Creates all the application contexts required and set up job registry entries with all the instances of `Job` found therein. Also closes the contexts when the enclosing context is closed.
      Specified by:
        `onApplicationEvent` in interface `org.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>`
      See Also:
        `InitializingBean.afterPropertiesSet()`

    - #### stop

          public void stop()

      Delegates to `JobLoader.clear()`.
      Specified by:
        `stop` in interface `org.springframework.context.Lifecycle`
      See Also:
        `Lifecycle.stop()`

    - #### start

          public void start()

      Take all the contexts from the factories provided and pass them to the `JobLoader`.
      Specified by:
        `start` in interface `org.springframework.context.Lifecycle`
      See Also:
        `Lifecycle.start()`

    - #### isRunning

          public boolean isRunning()

      Check if this component has been started.
      Specified by:
        `isRunning` in interface `org.springframework.context.Lifecycle`
      Returns:
        true if started successfully and not stopped
      See Also:
        `Lifecycle.isRunning()`