Re: [axonframework] Used entityManager in command dispatch interceptors

7 views
Skip to first unread message

Steven van Beelen

unread,
Sep 16, 2020, 6:21:05 AM9/16/20
to Axon Framework Users
Hi Aymen,

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:

@Bean
@ConditionalOnMissingBean
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!

Cheers,
Steven

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 https://discuss.axoniq.io/.
Hope to see you there!

On Sat, Aug 8, 2020 at 9:58 PM Aymen Kanzari <kanz...@gmail.com> wrote:
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 

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

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


`@Configuration
@AutoConfigureAfter(AxonAutoConfiguration.class)
public class AxonConfig {

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

}


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

private final EntityManager entityManager;

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

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

}`

--
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 axonframewor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/axonframework/699bd029-1b58-4986-bd1d-e9f63c5a262fn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages