Example usage for org.springframework.batch.integration.partition BeanFactoryStepLocator setBeanFactory

List of usage examples for org.springframework.batch.integration.partition BeanFactoryStepLocator setBeanFactory

Introduction

In this page you can find the example usage for org.springframework.batch.integration.partition BeanFactoryStepLocator setBeanFactory.

Prototype

public void setBeanFactory(BeanFactory beanFactory) throws BeansException 

Source Link

Usage

From source file:io.spring.batch.configuration.JobConfiguration.java

@Bean
@ServiceActivator(inputChannel = "inboundRequests", outputChannel = "outboundStaging")
public StepExecutionRequestHandler stepExecutionRequestHandler() {
    StepExecutionRequestHandler stepExecutionRequestHandler = new StepExecutionRequestHandler();

    BeanFactoryStepLocator stepLocator = new BeanFactoryStepLocator();
    stepLocator.setBeanFactory(this.applicationContext);
    stepExecutionRequestHandler.setStepLocator(stepLocator);
    stepExecutionRequestHandler.setJobExplorer(this.jobExplorer);

    return stepExecutionRequestHandler;
}

From source file:org.springframework.batch.integration.partition.RemotePartitioningWorkerStepBuilder.java

/**
 * Create an {@link IntegrationFlow} with a {@link StepExecutionRequestHandler}
 * configured as a service activator listening to the input channel and replying
 * on the output channel./* www  . j  a v  a2 s  .  c  om*/
 */
private void configureWorkerIntegrationFlow() {
    Assert.notNull(this.inputChannel, "An InputChannel must be provided");
    Assert.notNull(this.jobExplorer, "A JobExplorer must be provided");

    if (this.stepLocator == null) {
        BeanFactoryStepLocator beanFactoryStepLocator = new BeanFactoryStepLocator();
        beanFactoryStepLocator.setBeanFactory(this.beanFactory);
        this.stepLocator = beanFactoryStepLocator;
    }
    if (this.outputChannel == null) {
        if (logger.isDebugEnabled()) {
            logger.debug("The output channel is set to a NullChannel. "
                    + "The master step must poll the job repository for workers status.");
        }
        this.outputChannel = new NullChannel();
    }

    StepExecutionRequestHandler stepExecutionRequestHandler = new StepExecutionRequestHandler();
    stepExecutionRequestHandler.setJobExplorer(this.jobExplorer);
    stepExecutionRequestHandler.setStepLocator(this.stepLocator);

    StandardIntegrationFlow standardIntegrationFlow = IntegrationFlows.from(this.inputChannel)
            .handle(stepExecutionRequestHandler, SERVICE_ACTIVATOR_METHOD_NAME).channel(this.outputChannel)
            .get();
    IntegrationFlowContext integrationFlowContext = this.beanFactory.getBean(IntegrationFlowContext.class);
    integrationFlowContext.registration(standardIntegrationFlow).autoStartup(false).register();
}