Axon Server Command Handler Not Found

I have downloaded axon server 4.0.2 and run it locally via the java -jar axonserver.jar
Whenever I issue a command, the axon server responds with:

WARN 13332 — [-worker-ELG-3-1] i.a.a.message.command.CommandDispatcher : No Handler for command: test.axon.domain.command.RegisterAggregateCommand

I am not using spring-boot. Below is some extracts of my code:

`
public class Activator {

public static void main(String[] args) throws Exception {
Configurer configurer = DefaultConfigurer.defaultConfiguration()
.configureAggregate(MyAggregate.class)
.eventProcessing((eventProcessingConfigurer) -> eventProcessingConfigurer.registerEventHandler(configuration -> new AggregateEventHandler()));
Configuration configuration = configurer.buildConfiguration();

AggregateController controller = new AggregateController(new DefaultCommandGateway.Builder().commandBus(configuration.commandBus()).build());
String myId = UUID.randomUUID().toString();
controller.registerAggregate(myId);
controller.updateAggregate(myId);
}

}
`

`
@AggregateRoot
public class MyAggregate {

@AggregateIdentifier
private String myId;
private boolean hasRegistered;

protected MyAggregate() {
//constructor needed by Axon
}

@CommandHandler
public MyAggregate(RegisterAggregateCommand command) {
System.out.println(“Constructing MyAggregate”);
apply(new AggregateRegisteredEvent(command.getMyId()));
}

@EventSourcingHandler
public void on(AggregateRegisteredEvent event) {
System.out.println(“Test Reg Event”);
this.myId = event.getMyId();
hasRegistered = true;
}

@CommandHandler
public void handle(UpdateAggregateCommand command) {
System.out.println(“Test Upd Event”);
if (!hasRegistered) {
throw new IllegalStateException(“Cannot update a aggregate that hasn’t been registered”);
}
apply(new AggregateUpdatedEvent(command.getMyId()));
}

@CommandHandler
public void handle(DeleteAggregateCommand command) {
if (!hasRegistered) {
throw new IllegalStateException(“Cannot delete an aggregate that hasn’t been registered”);
}
apply(new AggregateDeletedEvent(command.getMyId()));
}

@EventSourcingHandler
public void on(AggregateDeletedEvent event) {
this.myId = event.getMyId();
hasRegistered = false;
}

}
`

`
public class RegisterAggregateCommand {

@TargetAggregateIdentifier
private final String myId;
private final String someField;

public RegisterAggregateCommand(String myId, String someField) {
this.myId = myId;
this.someField = someField;
}

public String getMyId() {
return myId;
}

public String getSomeField() {
return someField;
}

@Override
public int hashCode() {
int hash = 7;
hash = 89 * hash + (this.myId != null ? this.myId.hashCode() : 0);
return hash;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final RegisterAggregateCommand other = (RegisterAggregateCommand) obj;
if ((this.myId == null) ? (other.myId != null) : !this.myId.equals(other.myId)) {
return false;
}
return true;
}

@Override
public String toString() {
return “RegisterAggregateCommand{” + “myId=” + myId + ‘}’;
}

}
`

`
public class AggregateController {

private final CommandGateway commandGateway;

public AggregateController(CommandGateway commandGateway) {
this.commandGateway = commandGateway;
}

public void registerAggregate(String myId) throws Exception {
System.out.println("Registering aggregate with id: " + myId);
commandGateway.sendAndWait(new RegisterAggregateCommand(myId, “Test Company Inc.”));
System.out.println(“Aggregate Registered”);
}

public void updateAggregate(String myId) throws Exception {
System.out.println("Updating aggregate with id: " + myId);
commandGateway.sendAndWait(new UpdateAggregateCommand(myId, “Cool Company Inc.”));
System.out.println(“Aggregate Updated”);
}

}
`

Why does axon server not recognize my command handler? My aggregate has @CommandHandler annotated methods.

Hi,

the problem is that the configuration hasn’t received a start signal yet. Subscriptions (and connections to AxonServer) are only initiated when the configuration is started.
Instead of buildConfiguration(), just use start().
Alternatively, you can call start on your Configuration instance as well.

Hope this helps.
Cheers,

Allard

Geez, that was it.

Thanks Allard for helping. I feel so stupid now.

No need to. It’s the smallest details that are easiest to overlook.
Just glad I could help.

Cheers,