Я пытаюсь создать базовое приложение Axon / Spring с помощью учебника, но столкнулся со странной ошибкой, такой как: NoHandlerForCommandException: ни один обработчик не подписан на команду.Кажется, что Аксон не может видеть аннотацию @CommandHandler.
Здесь мои файлы:
агрегат
@Aggregate
@NoArgsConstructor
public class Account {
@AggregateIdentifier
private UUID accountId;
private Double balance;
@CommandHandler
public Account(CreateAccountCommand command) {
apply(new AccountCreatedEvent(command.getAccountId(), command.getName()));
}
@EventSourcingHandler
protected void on(AccountCreatedEvent event) {
this.accountId = event.getAccountId();
this.balance = 0.0;
}
}
событие
@AllArgsConstructor
@Getter
public class AccountCreatedEvent {
private UUID accountId;
private String name;
}
команда
@Getter
public class CreateAccountCommand {
@TargetAggregateIdentifier
private UUID accountId;
private String name;
public CreateAccountCommand(UUID accountId, String name) {
this.accountId = accountId;
this.name = name;
}
}
пружинный загрузочный конф
@SpringBootApplication
public class App {
@Configuration
public static class TestConfiguration {
@Bean
public EventStorageEngine inMemoryEventStorageEngine() {
return new InMemoryEventStorageEngine();
}
}
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
вот так я отправляю cmd
@Component
public class AppLoader {
@Autowired
private CommandGateway cmdGateway;
@PostConstruct
public void init() {
cmdGateway.send(new CreateAccountCommand(UUID.randomUUID(), "test"));
}
}
мой build.gradle
buildscript {
ext {
springBootVersion = '2.0.5.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'io.yourpoint.nettnews'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'org.axonframework', name: 'axon-test', version: '3.3.5'
compile group: 'org.axonframework', name: 'axon-spring-boot-starter', version: '3.3.5'
compile('org.springframework.boot:spring-boot-starter-webflux')
compileOnly('org.projectlombok:lombok')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('io.projectreactor:reactor-test')
}