Resource injection not configured for Sagas in Axon 3

Hi, long time no see Axon! :slight_smile:

It seems like the resource injector is not setup properly in Axon 3.

Using out of the box axon-spring doesn’t give me a configured resource injector and trying to wire up the configuration myself using the ModuleConfiguration SagaConfiguration does not let me.

I think the only way would be to set up all the components myself.

Wanted to check if this is a known bug/limitation or if perhaps I’m on the wrong track here.

Cheers,
Ted Steen

Hi Ted,

yeah, it’s a known bug. Is already fixed, but nit released yet. Will happen soon…

Cheers,

Allard

Is the bug present for @EventHandler ?
I found it using @EnableAxonAutoConfiguration even with @Order(Ordered.LOWEST_PRECEDENCE)
It seems that axon will instanciate the bean before Spring boot, and than Spring can’t inject resources such as JPARepository

Is yes how to workaround it?

I found a Workaround but it is very bad:

`
public static void main(final String[] args) {

final ApplicationContext ctx = SpringApplication.run(SsppApplication.class, args);

final RisorsaEventHandler r = ctx.getBean(RisorsaEventHandler.class);
final RisorsaQueryRepository repo = ctx.getBean(RisorsaQueryRepository.class);
r.setRisorsaQueryRepository(repo);
`

The issue has been found and fixed. It will be part of the next release.

It had to do with the timing of the Axon components being registered with Axon. It happened too early, preveting these beans from being autowired properly.

Cheers,

Allard

I’ve hit a similar issue.

My EventStorageEngine bean is being ignored and keeps defaulting to the InMemoryEventStorage
Any timeline with this release Allard? Or anyway i can access that snapshot?

Hi Kirk,

can you share a sample of your configuration? It may be something else in this case.
The next release will be made this week. It will be an M5 or RC1 release, depending on whether we manage to get certain fixes in.

Cheers,

Allard

I was tweaking the current AxonBank sample:

I tweaked the following in DistributedCommandBusConfig:

`

// @Bean
public EventStorageEngine postgresEventStorageEngine(Serializer serializer) {
return new PostgresEventStorage(entityManagerProvider(), springTransactionManager(), serializer);
}

// @Bean
// public EventStorageEngine eventStorageEngine() throws Exception {
// return new JpaEventStorageEngine(entityManagerProvider(), springTransactionManager());
// }

@Bean
public SagaStore postgresJPASagaStore(Serializer serializer) {
return new PostgresJsonSagaStore(serializer, entityManagerProvider());
}

@Bean
public EventStore eventStore(EventStorageEngine eventStorageEngine, Serializer serializer) {
return new EmbeddedEventStore(postgresEventStorageEngine(serializer));
}
`

Essentially, when i comment out the last ‘eventStore’ bean, i kept on getting the InMemoryStorageEngine bean.
I added a Custom postgres event storage engine - using JsonB as the payload. I can pass that code alone if it will help.

I cannot reproduce this on my local environment. It seems to work fine.
In you code snippet, there is a comment in front of the @Bean. Is that just a copy past issue, or is that there in your code as well?

Cheers,

Allard