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

Upcasters are not executed in the desired order when using @Order annotation on Bean Creation Methods in a Spring Environment #1892

Closed
nils-christian opened this issue Jul 20, 2021 · 3 comments
Assignees
Labels
Priority 4: Would Lowest priority. Would-be-nice to include issues when time allows it. Status: Resolved Use to signal that work on this issue is done. Type: Enhancement Use to signal an issue enhances an already existing feature of the project.
Milestone

Comments

@nils-christian
Copy link
Contributor

This is a follow up of issue #1810.

Basic information

Steps to reproduce

Clone the referenced repository. It contains a Spring Boot application (de.rhocas.axontest.axontest.AxontestApplication).
The application imports a Spring configuration containing three upcaster beans whose orders are defined by using Spring's @order annotation.

Expected behaviour

Upcaster1 is invoked before Upcaster2 and Upcaster2 before Upcaster3.

Actual behaviour

The actual order cannot be determined, but is usually 3, 1, and 2 on my machine.

The problem is, that the solution for #1810 only works if the Order annotation is used on the classes and only if the bean type is the annotated class. The code in org.axonframework.spring.config.SpringAxonAutoConfigurer.registerEventUpcasters(Configurer) uses beanFactory.getType which would return org.axonframework.serialization.upcasting.event.EventUpcaster in my case. Even if I would define the beans with Upcaster1 etc. there would still be no annotation, as the annotation is on the bean declaration not on the bean class itself.

@nils-christian nils-christian added the Type: Bug Use to signal issues that describe a bug within the system. label Jul 20, 2021
@smcvb
Copy link
Member

smcvb commented Jul 20, 2021

Thanks as always for drafting up an issue @nils-christian.
Although I think this wasn't clear anywhere from the documentation, what you describe is a new limitation.
As such it is more a documentation bug and an enhancement request.

I'll go look for a resolution for this, if at all possible.
The fact we don't get the bean, but the type, is to ensure that we do not initialize the upcasters too early in the configuration process.
The stage when the Spring Axon Configurer kicks in should only register the upcasters and in that function retrieve the bean.
Otherwise, Axon will come too early in the process, getting a higher chance of circular dependencies.

Lastly, I think it is clear what the workaround would be in your case.
Namely adding the annotation to the class of the upcaster instead of on the bean creation method.
Another option would be to register all the upcasters manually in an EventUpcasterChain, of course.

I hope this clarifies our intent and your options for now Nils!

@smcvb smcvb added the Priority 3: Could Low priority. Issues that are nice to have but have a straightforward workaround. label Jul 20, 2021
@smcvb smcvb self-assigned this Jul 20, 2021
@smcvb smcvb changed the title Spring: Upcasters are not executed in the correct order Upcasters are not executed in the desired order when using @Order annotation on Bean Creation Methods in a Spring Environment Jul 20, 2021
@smcvb smcvb added Priority 4: Would Lowest priority. Would-be-nice to include issues when time allows it. Type: Enhancement Use to signal an issue enhances an already existing feature of the project. and removed Priority 3: Could Low priority. Issues that are nice to have but have a straightforward workaround. Type: Bug Use to signal issues that describe a bug within the system. labels Jul 20, 2021
@smcvb
Copy link
Member

smcvb commented Jul 21, 2021

Good news, think I've found a solution. I will draft up a PR shortly!

@smcvb smcvb added the Status: In Progress Use to signal this issue is actively worked on. label Jul 21, 2021
@smcvb smcvb added this to the Release 4.5.4 milestone Jul 21, 2021
smcvb added a commit that referenced this issue Jul 21, 2021
The AnnotationAwareOrderComparator does not check for the annotation on
bean creation methods, but only on the classes themselves. We can
instead use the findAnnotationOnBean(beanName, Order.class) method to
get the ordering from any bean creation spot. This allows us to support
the @order annotation on @bean annotated methods or fields too.

#1892
smcvb added a commit that referenced this issue Jul 21, 2021
[#1892] Adjust Upcaster ordering logic in Spring environments
@smcvb
Copy link
Member

smcvb commented Jul 21, 2021

Closing this issue since pull request #1895 resolves it.

@smcvb smcvb closed this as completed Jul 21, 2021
@smcvb smcvb added Status: Resolved Use to signal that work on this issue is done. and removed Status: In Progress Use to signal this issue is actively worked on. labels Jul 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority 4: Would Lowest priority. Would-be-nice to include issues when time allows it. Status: Resolved Use to signal that work on this issue is done. Type: Enhancement Use to signal an issue enhances an already existing feature of the project.
Projects
None yet
Development

No branches or pull requests

2 participants