Class AsyncExecutorConfiguration

  • All Implemented Interfaces:
    org.springframework.beans.factory.Aware, org.springframework.beans.factory.config.BeanFactoryPostProcessor, org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor, org.springframework.context.EnvironmentAware, org.springframework.scheduling.annotation.AsyncConfigurer

    @Configuration
    @Import({DataSourceProxyConfiguration.class,TaskListenerFactoryConfiguration.class})
    @EnableAsync
    public class AsyncExecutorConfiguration
    extends Object
    implements org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor, org.springframework.scheduling.annotation.AsyncConfigurer, org.springframework.context.EnvironmentAware
    Configuration class to set up asynchronous executors.

    The loaded configuration properties are themselves registered as a bean, so they may be in other classes needing them, see EXECUTOR_CONFIGURATION_PROPERTIES.

    For each configured task a bean DelegatingExecutor with the name {system_name}.{task_name} is created. The task's configured executor is set in the DelegatingExecutor as it's delegate.

    A method annotated with Async can specify its full task name, i.e. {system_name}.{task_name} as the annotation value. The corresponding delegating executor bean will be retrieved by this name.

    NOTE: each async task MUST be specified in the configuration, otherwise an exception will be raised.

    Since:
    2.0.0
    Author:
    Rutger Lubbers, Paul Klos
    • Field Detail

      • ASYNC_TIMEOUT_EXECUTOR

        public static final String ASYNC_TIMEOUT_EXECUTOR
        Async (task) timeout executor bean name.
        See Also:
        Constant Field Values
    • Constructor Detail

      • AsyncExecutorConfiguration

        public AsyncExecutorConfiguration()
    • Method Detail

      • postProcessBeanDefinitionRegistry

        public void postProcessBeanDefinitionRegistry​(@NonNull
                                                      org.springframework.beans.factory.support.BeanDefinitionRegistry registry)
                                               throws org.springframework.beans.BeansException
        Specified by:
        postProcessBeanDefinitionRegistry in interface org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor
        Throws:
        org.springframework.beans.BeansException
      • postProcessBeanFactory

        public void postProcessBeanFactory​(@NonNull
                                           org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory)
                                    throws org.springframework.beans.BeansException

        Configured method names are aliased to their corresponding executor, such that bean lookup works.

        Specified by:
        postProcessBeanFactory in interface org.springframework.beans.factory.config.BeanFactoryPostProcessor
        Throws:
        org.springframework.beans.BeansException
      • getAsyncExecutor

        public Executor getAsyncExecutor()
        Specified by:
        getAsyncExecutor in interface org.springframework.scheduling.annotation.AsyncConfigurer
        Returns:
        the default executor.
      • getAsyncUncaughtExceptionHandler

        public org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler()
        Specified by:
        getAsyncUncaughtExceptionHandler in interface org.springframework.scheduling.annotation.AsyncConfigurer
        Returns:
        null, i.e. use the Spring default
      • setEnvironment

        public void setEnvironment​(@NonNull
                                   org.springframework.core.env.Environment environment)

        Use the environment to obtain the location of the configuration file.

        Specified by:
        setEnvironment in interface org.springframework.context.EnvironmentAware
      • setAsyncPropertiesLoader

        public void setAsyncPropertiesLoader​(AsyncPropertiesLoader asyncPropertiesLoader)
        Setter for the properties loaded.

        Added for testability.

        Parameters:
        asyncPropertiesLoader - the loader