Hiya
I’m having an issue with creating a snapshot in Axon v3.1.
Brian Sanders was kind enough to provide some sample code, and I’ve just extended it to try and introduce support for snapshots.
The snapshot code was taken from some code I had working in Axon v2.
The error I am getting is that when I request a snapshot I get the following error:
An attempt to create and store a snapshot resulted in an exception. Exception summary: Unable to resolve parameter 1 (PasswordHashGenerator) in handler public void com.sample.user.UserAggregate.authenticateUser(com.sample.user.commands.AuthenticateUser,com.sample.user.crypto.PasswordHashGenerator)
The method it is having problems with is defined as follows:
@CommandHandler
public void authenticateUser(AuthenticateUser cmd, PasswordHashGenerator passwordHashGenerator) {
if (passwordHashGenerator.validatePasswordHash(cmd.getPassword(), getPasswordHash())) {
apply(new UserAuthenticated(getId()));
} else {
apply(new UserAuthenticationFailed(getId()));
}
}
The snapshotter class is defined as follows:
@Slf4j
@Component
public class UserSnapshotter {
@Autowired
private AggregateSnapshotter snapshotter;
@Autowired
private EventStore store;
public void createSnapshot(String aggregateIdentifier) {
snapshotter.scheduleSnapshot(UserAggregate.class, aggregateIdentifier);
log.info("SCHEDULED A SNAPSHOT!");
}
}
and it’s called from the Web controller as follows:
@Autowired
private UserSnapshotter shotter;
@PutMapping(path = "{id}/snapshot")
public void snapshot(@PathVariable String id) {
shotter.createSnapshot(id);
}
The full source code is in this repository here: https://github.com/deevodavis71/sample-user-service
It’s important to me that I can use Spring Boot with Axon as we already have an extensive set of code using Spring, and if I’m to convince my team to use Event Sourcing and CQRS then to not use Spring would be a step too far…
Any ides how I get around the issue?
Kind regards
Steve