Cannot spawn a new aggregate from aggregate : Repository provider not provided

Hello everyone,

I have been trying to make some integration tests pass by calling some rest controllers on top of aggregates and I am stuck with the following error while trying to create an aggregate from within another aggregate :

java.lang.RuntimeException: org.axonframework.common.AxonConfigurationException: Since repository provider is not provided, we cannot spawn a new aggregate…

Tests have been ok with Fixtures, around the aggregates. I have been able to load an event sourced aggregate, wich created a new aggregate in one of its command handling methods
It seems that Fixtures are packaged with a default repository Provider that allow the creation of aggregates.

I need to make it work in integration phase before production with is the next step.

Any help regarding this problem would be greatly appreciated.

Regards,

Benjamin.

any ideas?
As a work-around, I had to use an event Listenner that send a creation command as seen in the axon-trader application.
What am I missing to have such an error? I thought a repositoryProvider was gathered by default with each Repository Bean declaration.

Thank in advance.

Benjamin.

Hi Benjamin,

can you share some of your configuration? Axon does indeed automatically inject the RepositoryProvider, depending on how you configure it.

Also note that this feature will only work if both aggregates are in the same deployment/configuration/Spring Context.

Cheers,

Allard

Hello Allard, thank you for your reply.

Here is the configuration of the repository.
It 's a repository based on aggregate of type Aliment.
Aliments must be created from another aggregate which is of type Contrat.
Then the aliment can have his own lifecycle dealing with commands. Both aggregate must use spring injected beans.

Maybe it’s impossible de create beans using new if in another hand you declare a SpringPrototypeAggregateFactory
to instantiate them.

@Bean
public Repository<Contrat> contratRepository(EventStore eventStore, Snapshotter snapshotter, @Value("${axon.event.count.snapshot}") int threshold,
                                             MultiParameterResolverFactory factory, @Qualifier("aggregatFactoryForContrat")
                                             final SpringPrototypeAggregateFactory<Contrat> springPrototypeAggregateFactory) {
    return new EventSourcingRepository<>(springPrototypeAggregateFactory, eventStore, factory,
                                         new EventCountSnapshotTriggerDefinition(snapshotter, threshold));
}


Hello,

anyone has an advice for me?
IS this the configuration expected?
cheers.

Benjamin.

Hi Benjamin,

if you’re on Spring Boot, you don’t need to configure the repositories or aggregate factories yourself. Just annotate you Aggregate with @Aggregate. The “spawning aggregates from aggregates” feature will then work automatically. Just remove your configuration, in that case and define the EventCountSnapshotTriggerDefinition as a bean. In the @Aggregate annotation, use that bean’s name as the snapshotTriggerDefinition property.

Otherwise, the only thing you’re missing, is the RepositoryProvider, which you need to supply to your repositories. This is how Axon locates a repository when an aggregate needs to create another. Basically, it’s a function that must return a Repository for a given Class name.

Cheers,

Allard

Thank you Allard,

removing this useless configuration resolved my problem.

Have a good day !