Used entityManager in command dispatch interceptors

Skip to first unread message

eriksen alli

Aug 8, 2020, 4:00:57 PM8/8/20
to Axon Framework Users
Hello everyone,

I'm using Axon 4.3 with JPA/Spring.
I want to inject entityManager in my interceptor, so i used ContainerManagedEntityManagerProvider in my configuration. but i have this error when i run my application 

Parameter 0 of method configureCommandBus in AxonConfig required a bean of type 'org.axonframework.springboot.util.jpa.ContainerManagedEntityManagerProvider' that could not be found.

Consider defining a bean of type 'org.axonframework.springboot.util.jpa.ContainerManagedEntityManagerProvider' in your configuration.

public class AxonConfig {

public CommandBus configureCommandBus(org.axonframework.springboot.util.jpa.ContainerManagedEntityManagerProvider containerManagedEntityManagerProvider) {
CommandBus commandBus = SimpleCommandBus.builder().build();
new CatalogDispatchInterceptor(containerManagedEntityManagerProvider.getEntityManager()));
return commandBus;


public class CatalogDispatchInterceptor implements MessageDispatchInterceptor<CommandMessage<?>> {

private final EntityManager entityManager;

public CatalogDispatchInterceptor(EntityManager entityManager) {
this.entityManager = entityManager;

public BiFunction<Integer, CommandMessage<?>, CommandMessage<?>> handle(
List<? extends CommandMessage<?>> messages) {
return (index, command) -> {
(CreateCatalogCommand.class.isInstance(command.getPayloadType())) { }
return command;


Steven van Beelen

Sep 16, 2020, 6:22:51 AM9/16/20
to Axon Framework Users
Hi Eriksen,

If you are relying on the JpaAutoConfiguration to create the ContainerManagedEntityManagerProvider, it would be better to expect a bean of type EntityManagerProvider instead.
Stating this as the JpaAutoConfiguration does the following:

public EntityManagerProvider entityManagerProvider() {
    return new ContainerManagedEntityManagerProvider();

So, it returns an EntityManagerProvider, not a ContainerManagedEntityManagerProvider.
Could be wrong with my assumption here, but I am relatively confident Spring will see the former here as the thing to wire instead of the latter.

If this does not resolve your problem, then you are dealing with a spring ordering issue.
Might help to also add the JpaAutoConfiguration to you @AutoConfigureAfter annotation in that case.

Hoping this helps you further Aymen!


PS. It is important to note that this mailing list will be discontinued as specified in this thread.
Instead of this mailing list we have moved to use a forum style of communication, at
Hope to see you there!

You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
Reply all
Reply to author
0 new messages