nice work with finishing the 3.0 release just before this year ends
I’m experimenting with axon 3 through the release candidates now for a while and switched to the 3.0 release today. So far I’ve got a prototype web application running but ran into some trouble using a command handler class. Currently the injection point of the event sourcing repository in my command handler is not called. I’ve checked the new documentation (great work) but couldn’t find a hint on that. Here is the code of my command handler:
`
public class ParticipantLinkService {
private static Logger logger = LoggerFactory.getLogger(ParticipantLinkService.class);
private Repository<ParticipantAggregate> repository;
public ParticipantLinkService() {
logger.info("Service created");
}
public void setRepository(Repository<ParticipantAggregate> repository) {
this.repository = repository;
logger.info("Got repository {}", repository);
}
@CommandHandler
public void linkParticipants(LinkParticipants command) {
logger.info("Handling command {}", command);
// try to load participants to make sure they exist
ParticipantAggregate fromParticipant = (ParticipantAggregate) repository.load(command.getFromId().toString());
ParticipantAggregate toParticipant = (ParticipantAggregate) repository.load(command.getToId().toString());
// add relation
fromParticipant.beziehungKnüpfen(command.getRelationType(), command.getToId());
}
}
`
The command handler is called but results in a NullPointerException because the repository is not injected. Any help would be appreciated.
Frank.
P.S. A happy new year to you and all axon fellows on this news group.
if (repository != null) {
// try to load participants to make sure they exist
ParticipantAggregate fromParticipant = (ParticipantAggregate) repository.load(command.getFromId().toString());
ParticipantAggregate toParticipant = (ParticipantAggregate) repository.load(command.getToId().toString());
I’ve tried the @Inject with and without @Named as well as with setter injection instead of field injection.
I’m using axon within a jee web application and configured via DefaultConfigurer. As far as I understand the source code, the injection is then done using the ConfigurationResourceInjector which extends org.axonframework.eventhandling.saga.AbstractResourceInjector.
the ResourceInjector only works with Sagas, not with arbitrary beans (which I assume your Service is). Therefore, for injection, you would need to rely on your JEE container to inject your resources.