Used entityManager in command dispatch interceptors

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;


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!