Axonframework: Snapshotter not configured with Axon Spring Boot Starter

Created on 18 Dec 2018  Â·  7Comments  Â·  Source: AxonFramework/AxonFramework

When defining a custom SnapshotTriggerDefinition the docs: https://docs.axoniq.io/reference-guide/1.3-infrastructure-components/spring-boot-autoconfiguration#aggregate-configuration

State that:

Note that a Snapshotter instance, if not explicitly defined as a Bean already, will be automatically configured for you. This means you can simply pass the Snapshotter as a parameter to your SnapshotTriggerDefinition.

However, when I try the exact example in the docs I get the following:

2018-12-18 15:11:02.731 ERROR 52459 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of method eventCountSnapshotTriggerDefinition in gamesys.general.demo.axon.conf.AxonDemoConfiguration required a bean of type 'org.axonframework.eventsourcing.Snapshotter' that could not be found.

Everything else works as expected, repositories etc. are all auto-configured. Have i set something up incorrectly, or is the documentation out of date?

Axon version: 3.4.2 (+axon-mongo 3.4.2)
Spring boot version: 2.0.5.RELEASE

Should Resolved Bug

Most helpful comment

Hi,

After interacting with @smcvb I realized what is wrong.

I did some debugging, but did figure out why your SnapshotTriggerDefinition wasn't set on your GiftCard Aggregate.
The issue relates to the follow JavaDoc present on the @Aggregate anotation:

Note that the use of {@link #repository()} overrides this setting, as a repository explicitly defines the snapshot trigger definition.

Now, I know you didn't utilized the @Aggregate#repository field, but I did notice you created your own CachingEventSourcingRepository in the GcCommandConfiguration class.
The name Axon will configure an Aggregate's repository defaults to {aggregate-name}Repository.
As the bean name of the CachingEventSourcingRepository in that configuration class is giftCardRepository, the framework's configuration API thinks you've specified a repository for the aggregate yourself (which granted, you did).

Due too this, the SnapshotTriggerDefinition you defined in the AxonConfig was not taken into account by the configuration API, resulting in the behavior you've encountered.
I verified this was the problem by dropping the GcCommandConfiguration and starting up your sample application again.
After that and after creating a GiftCard through the UI and issuing some redeem operations, I correctly saw the SnapshotTriggerDefinition taking effect.

Concluding, if you want to configure both a caching repository and a snapshot trigger definition, you will be inclined, regardless, to use the AggregateConfigurer correctly.

Added, I feel the JavaDoc of the @Aggregate annotation should specify that an existing bean corresponding to the default naming strategy will also trigger the behavior of a SnapshotTriggerDefinition not to be taken into account.

All 7 comments

this is indeed a discrepancy between the docs and the framework. In this case, I'd consider it a bug/missing feature in the framework, as it should create a default snapshotter instance.

A quick workaround would be to define a SpringAggregateSnapshotter instance in your application context.

As mentioned above, the workaround trying to configure with SpringAggregateSnapshotter didn't work (I described here https://groups.google.com/forum/#!topic/axonframework/GnsCpFkHoFo).

@Bean public SnapshotTriggerDefinition mySnapshotTriggerDefinition(Snapshotter snapshotter) { return new EventCountSnapshotTriggerDefinition(snapshotter, 3); }
@Bean public SpringAggregateSnapshotterFactoryBean springAggregateSnapshotterFactoryBean() { return new SpringAggregateSnapshotterFactoryBean(); }

If I let only this code I get the same error described here in Axon 4.X.

@Bean public SnapshotTriggerDefinition mySnapshotTriggerDefinition(Snapshotter snapshotter) { return new EventCountSnapshotTriggerDefinition(snapshotter, 3); }

Any workaround? How can I proper configure snapshots to work with Axon 4.x?

@gustavomr, you should pair the introduction of your own SnapshotTriggerDefinition with adjusting the snapshotTriggerDefinition field in the @Aggregate for the Aggregate you want to define it to.

The snapshotTriggerDefinition field should resemble the Bean name you create, which in your sample would conclude to the following annotation on your Aggregate:

  • @Aggregate(snapshotTriggerDefinition = "mySnapshotTriggerDefinition")

Hope this helps!

Hi Steven,

I already did it and still not working :(

On Thu, 13 Jun 2019 at 10:14 Steven van Beelen notifications@github.com
wrote:

@gustavomr https://github.com/gustavomr, you should pair the
introduction of your own SnapshotTriggerDefinition with adjusting the
snapshotTriggerDefinition field in the @Aggregate for the Aggregate you
want to define it to.

The snapshotTriggerDefinition field should resemble the Bean name you
create, which in your sample would conclude to the following annotation on
your Aggregate:

  • @Aggregate(snapshotTriggerDefinition = "mySnapshotTriggerDefinition")

Hope this helps!

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/AxonFramework/AxonFramework/issues/932?email_source=notifications&email_token=AAESTHTQOQOOMQXLLPCRZ23P2JB27A5CNFSM4GLCAL2KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODXTUVKY#issuecomment-501697195,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAESTHTO34GOENXCIZSY52DP2JB27ANCNFSM4GLCAL2A
.

Would you be able to share the exact snippets of your:

  • Axon Configuration
  • Versions of Axon/Spring
  • Aggregate class

Without knowing the exact set up of your application, I am not really able to help you out @gustavomr.
The implementation to me suggests that what I shared would resolve it, hence the necessity for more input from your part.

Hi,

After interacting with @smcvb I realized what is wrong.

I did some debugging, but did figure out why your SnapshotTriggerDefinition wasn't set on your GiftCard Aggregate.
The issue relates to the follow JavaDoc present on the @Aggregate anotation:

Note that the use of {@link #repository()} overrides this setting, as a repository explicitly defines the snapshot trigger definition.

Now, I know you didn't utilized the @Aggregate#repository field, but I did notice you created your own CachingEventSourcingRepository in the GcCommandConfiguration class.
The name Axon will configure an Aggregate's repository defaults to {aggregate-name}Repository.
As the bean name of the CachingEventSourcingRepository in that configuration class is giftCardRepository, the framework's configuration API thinks you've specified a repository for the aggregate yourself (which granted, you did).

Due too this, the SnapshotTriggerDefinition you defined in the AxonConfig was not taken into account by the configuration API, resulting in the behavior you've encountered.
I verified this was the problem by dropping the GcCommandConfiguration and starting up your sample application again.
After that and after creating a GiftCard through the UI and issuing some redeem operations, I correctly saw the SnapshotTriggerDefinition taking effect.

Concluding, if you want to configure both a caching repository and a snapshot trigger definition, you will be inclined, regardless, to use the AggregateConfigurer correctly.

Added, I feel the JavaDoc of the @Aggregate annotation should specify that an existing bean corresponding to the default naming strategy will also trigger the behavior of a SnapshotTriggerDefinition not to be taken into account.

Thanks for sharing our private discussion on this @gustavomr, pretty sure others will benefit from this too. Added, I have updated the JavaDoc top specify this point we've discovered, hopefully serving as an additional pointer for framework users, which can be found in this commit.

Was this page helpful?
0 / 5 - 0 ratings