Upgrade from Axon 3.x to 4.10.1 - Token issue

I am currently upgrading my application from JDK8_Axon3.x+SpringBoot 1.4 to JDK17+axon 4.10.1 + Spring Boot 3.3.4

While fetching the token I get one of the following errors
Initially I received following error:
class org.axonframework.serialization.UnknownSerializedType cannot be cast to class org.axonframework.eventhandling.TrackingToken

I deleted all records from token_entry table and again ran the application. This time I started getting an error

class org.axonframework.eventhandling.ReplayToken cannot be cast to class org.axonframework.eventhandling.GapAwareTrackingToken

I’ve gone through some of the solutions on forums but haven’t been able to understand what needs to be done to fix this. Lots of forums mention fix already made in Axon 4.x where tokens from Axon 3.x are adapated in 4.x format although I am getting above error.

Can someone suggest what needs to be done to fix the issue?

PS: Not using Axon Server; Using Xstream serializer latest version

Hey @jinwalakv! I think I know what you’re missing.

Between AF3 and AF4, the GapAwareTrackingToken and GlobalSequenceTrackingToken changed their package. Hence, a stored format from AF3 would not work out of the box for AF4.

Axon Framework has the axon-legacy module to support migrations like this. The axon-legacy module contains a (deprecated) version of both the GapAwareTrackingToken and GlobalSequenceTrackingToken with the old package reference.

Thus, to deserialize the old tokens, adding axon-legacy should suffice.

Why you are receiving the class org.axonframework.eventhandling.ReplayToken cannot be cast to class org.axonframework.eventhandling.GapAwareTrackingToken isn’t entirely clear to me, though. Perhaps you can give the full stack trace instead of only the final message?