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

Spring: HierarchicalBeanFactory is not supported #1055

Closed
OLibutzki opened this issue Apr 16, 2019 · 3 comments
Closed

Spring: HierarchicalBeanFactory is not supported #1055

OLibutzki opened this issue Apr 16, 2019 · 3 comments
Assignees
Labels
Priority 2: Should High priority. Ideally, these issues are part of the release they’re assigned to. 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

@OLibutzki
Copy link
Contributor

In our application we use Spring Boot's hierarchical application contexts. We have a parent (root) context which maintains all the Axon infrastructure beans (like EventBus, EventStore, CommandGateway, CommandBus,...). Then there are child contexts which use these beans and provide handlers (CommandHandler, EventHandler, QueryHandler).

Unfortunately Axon's Spring integration relies on org.springframework.beans.factory.ListableBeanFactory.getBeansOfType(Class). which does not support hierarchical bean factories. Quote form Javadoc:

Does not consider any hierarchy this factory may participate in. Use BeanFactoryUtils' beansOfTypeIncludingAncestors to include beans in ancestor factories too.

There are a couple of other methods which need to be adjusted in order to support hierarchical application context / bean factories...

I created a sample project to illustrate the problem (master): https://github.com/OLibutzki/axon-hierarchical

In the Branch hierarchy-aware I modified org.axonframework.spring.config.SpringAxonAutoConfigurer and org.axonframework.spring.config.CommandHandlerSubscriber. This leads to a working example.

You have to adjust a couple of other classes in order to support hierarchical bean factories, but my code should indicate how to fix this issue.

@abuijze abuijze added Priority 2: Should High priority. Ideally, these issues are part of the release they’re assigned to. Type: Enhancement Use to signal an issue enhances an already existing feature of the project. labels Apr 16, 2019
@abuijze
Copy link
Member

abuijze commented Apr 16, 2019

Hi @OLibutzki,

thanks for reporting that. It should be fairly trivial to change that, without undesired side-effects. If you're up for the challenge, and are open to creating a PR for this, don't hesitate ;-). Otherwise, we'll pick this up as soon as we've got time for it.

@OLibutzki
Copy link
Contributor Author

OLibutzki commented Apr 18, 2019

Hi @abuijze,

thanks for your feedback. The outlook that this will be supported is great news for us. Otherwise this might be a blocker in our project. I will try to supply a PR (hopefully next week).

In the meantime the sample at my playground turned into a blueprint on how to use Axon with hierarchical spring application contexts.

There are two "business modules": module1 and module2. Each of them has a separate jpa token and saga store. The third module is the Axon module which provides the infrastructure stuff like (Event Store (JPA based), Event Bus, Command Bus,...
In this module only the snapshots and domain events are stored. The Axon module exposes some beans (like commandGateway) to the root context so they are accessible from the other modules.

Because of Axon's decent AutoConfiguration facilities the child modules pick up these exposed beans instead of building a separate bean. That's the reason why the other child modules do not use their own event store, command gateway, etc., but us the one provided by the axon module.

Things seem to work like a charm. I'm going to migrate my project from our own solution towards Axon now. Maybe there will pop up some new issues...

OLibutzki added a commit to OLibutzki/AxonFramework that referenced this issue Apr 25, 2019
Signed-off-by: Oliver Libutzki <oliver.libutzki@bmiag.de>
@smcvb smcvb added the Status: In Progress Use to signal this issue is actively worked on. label May 6, 2019
@smcvb smcvb added this to the Release 4.2 milestone May 6, 2019
smcvb added a commit that referenced this issue May 6, 2019
[#1055] Support for hierarchical application contexts added
@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 May 6, 2019
@smcvb
Copy link
Member

smcvb commented May 6, 2019

Closing this issue as it has been resolved in PR #1071

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority 2: Should High priority. Ideally, these issues are part of the release they’re assigned to. 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

3 participants