No handler was subscribed to command [commands.CreateAccountCommand]

1,320 views
Skip to first unread message

S. Van Overmeire

unread,
Jan 13, 2017, 9:48:30 AM1/13/17
to Axon Framework Users
Hi, 

I've been following along with your axon 3.0 video: https://www.youtube.com/watch?v=s2zH7BsqtAk. I created the application, but when I get to starting the spring boot main, I get a "No handler was subscribed to command [commands.CreateAccountCommand]" exception. 

Not really sure what is wrong, because the only difference seems to be that I simplified things a bit & @EnableAxonAutoConfiguration seems to have been replaced by @EnableAxon.

Any ideas?

Thanks,

Sam

____________________________________________________________________________________


import commands.CreateAccountCommand;
...
import static org.axonframework.commandhandling.model.AggregateLifecycle.apply;

@Aggregate
public class Account {

@AggregateIdentifier
private String ourId;

public Account() {
}

public Account(String ourId) {
this.ourId = ourId;
}

@CommandHandler
public Account(CreateAccountCommand command) {
apply(new AccountCreatedEvent(command.getAccountId()));
}

@EventSourcingHandler
public void on(AccountCreatedEvent event) {
this.ourId = event.getId();
}

public String getOurId() {
return ourId;
}

public void setOurId(String ourId) {
this.ourId = ourId;
}
}



public class CreateAccountCommand {

private String accountId;

public CreateAccountCommand() {
}

public CreateAccountCommand(String accountId) {
this.accountId = accountId;
}

public String getAccountId() {
return accountId;
}
}



public class AccountCreatedEvent {

private String id;

public AccountCreatedEvent() {
}

public AccountCreatedEvent(String id) {
this.id = id;
}

public String getId() {
return id;
}
}



import commands.CreateAccountCommand;
...

import static org.axonframework.commandhandling.GenericCommandMessage.asCommandMessage;

@EnableAxon
@SpringBootApplication
public class MyApplication {

public static void main(String[] args) {
ConfigurableApplicationContext run = SpringApplication.
run(MyApplication.class);
CommandBus commandBus = run.getBean(CommandBus.
class);

commandBus.dispatch(
asCommandMessage(new CreateAccountCommand("exampleId")));
}



@Bean
public EventStorageEngine eventStorageEngine() {
return new InMemoryEventStorageEngine();
}
}



public class AccountTest {

private AggregateTestFixture<Account> accountAggregateTestFixture;

@Before
public void setup() {
accountAggregateTestFixture = new AggregateTestFixture<>(Account.class);
}

@Test
public void aTest() {
accountAggregateTestFixture.givenNoPriorActivity()
.when(new CreateAccountCommand("anId"))
.expectEvents(new AccountCreatedEvent("anId"));
}
}

Allard Buijze

unread,
Jan 14, 2017, 1:47:51 AM1/14/17
to Axon Framework Users
What package are all your classes in? More importantly, is your aggregate in a subpackage of the one your Application class is in?

If you use Spring Boot, you better off including the axon-spring-boot-starter instead of using the annotation.

Cheers,

Allard
--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframewor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

S. Van Overmeire

unread,
Jan 16, 2017, 3:03:24 AM1/16/17
to Axon Framework Users
Well, that was a stupid mistake. The aggregate was indeed not in a subpackage of the application class... I also removed the annotation and added axon-spring-boot-starter.

Thanks!
Reply all
Reply to author
Forward
0 new messages