Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple task listener beans of same type #796

Merged

Conversation

isikerhan
Copy link
Contributor

Hello,

In a Spring Cloud Task application, when I have more than one beans of task listeners with @BeforeTask, @AfterTask and/or @FailedTask of same type (or different types inheriting the same @BeforeTask/@AfterTask/@FailedTask method), only single one of those listener beans work. Listener methods of the rest of the beans are never invoked. Please see the following example.

public class TaskListener {

    @BeforeTask
    public void beforeTask(TaskExecution taskExecution) {
        // ...
    }
}

@Configuration
public class ListenerConfiguration {
    
    // this bean's beforeTask method is never called
    @Bean
    public TaskListener taskListener() {
        return new TaskListener();
    }

    @Bean
    public TaskListener otherTaskListener() {
        return new TaskListener();
    }
}

I don't know if this is the intended behaviour but this is an unexpected behaviour to me and not documented AFAIK. This behaviour also causes multi-step partitioned tasks to fail with NPE since DeployerPartitionHandler uses @BeforeTask to inject TaskExecution. (See #793)

This PR changes this behaviour so that all listener methods are invoked even the listener beans have the same type (or different types inheriting the same listener method) I've added some unit tests as well to cover "multiple listener beans of same type" case. I've also tested these changes with a multi-step partitioned task and it just seemed to work fine.

Thanks.

@cppwfs
Copy link
Collaborator

cppwfs commented Aug 16, 2021

@isikerhan Thank you for this contribution! If you can sign the Contributor License Agreement, I can merge this PR.

@cppwfs
Copy link
Collaborator

cppwfs commented Aug 16, 2021

Ahh. You have already signed it. Sorry I missed that!

@cppwfs cppwfs merged commit 8b43520 into spring-cloud:main Aug 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants