没有处理程序订阅命令。轴突 3.3
No handler was subscribed to command. Axon 3.3
我试图通过教程创建基本的 Axon/Spring 应用程序,但遇到了奇怪的错误,例如:NoHandlerForCommandException:没有处理程序订阅命令。好像Axon看不到@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;
}
}
spring 启动配置
@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);
}
}
这就是我发送命令的方式
@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')
}
很可能在 @PostConstruct
中执行 CommandGateway#send()
调用对于 Axon 来说太早了..
按照目前的情况,所有命令、事件和查询处理程序通常会在在 初始化所有 bean 之后注册。
将 CommandGateway#send()
移到 REST 端点后面应该会给您足够长的时间来确保所有处理程序都已注册。
所以简而言之,你得到 NoHandlerForCommandException
.
的时间问题
我们(在 AxonIQ)看到了在所有处理程序都已注册后立即发送某种应用程序事件的好处。不过那是以后的事了。
希望这对你有帮助 @Benjamin!
我试图通过教程创建基本的 Axon/Spring 应用程序,但遇到了奇怪的错误,例如:NoHandlerForCommandException:没有处理程序订阅命令。好像Axon看不到@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;
}
}
spring 启动配置
@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);
}
}
这就是我发送命令的方式
@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')
}
很可能在 @PostConstruct
中执行 CommandGateway#send()
调用对于 Axon 来说太早了..
按照目前的情况,所有命令、事件和查询处理程序通常会在在 初始化所有 bean 之后注册。
将 CommandGateway#send()
移到 REST 端点后面应该会给您足够长的时间来确保所有处理程序都已注册。
所以简而言之,你得到 NoHandlerForCommandException
.
我们(在 AxonIQ)看到了在所有处理程序都已注册后立即发送某种应用程序事件的好处。不过那是以后的事了。
希望这对你有帮助 @Benjamin!