【问题标题】:Axon 3 not found handlerAxon 3 未找到处理程序
【发布时间】:2017-10-18 19:14:49
【问题描述】:

我是 Java 初学者。我只会为工作和处理命令配置我的处理程序。此时我收到ExceptionNo handler was subscribed to command [com.capgemini.books.CreateBook]

我的代码如下:

@Configuration
public class ControllerConfig {
    @Bean
    public CommandBus commandBus() {
        return new SimpleCommandBus();
    }
}

public class CreateBookHandler {
    public CreateBookHandler() { }

    @CommandHandler
    public void handle(CreateBook command) {
       Book newBook = new Book(1001L, "anonymous", command.bookTitle());
    }
}

【问题讨论】:

    标签: java spring dependency-injection annotations axon


    【解决方案1】:

    希望我能帮到你:-)

    假设您正在通过 Spring Boot 运行您的应用程序,并且您正在使用 axon-spring-boot-starter 依赖项自动连接所有内容,那么我知道您缺少什么。 CreateBookHandler 不是 Spring Bean,因此 Axon 的自动布线设置不会将其视为 bean,因此无法在其上找到 @CommandHandler 注释函数。

    此外,我通常会将我的命令处理函数直接放在聚合上,而不是放在我的设置中的单独组件中。原因是因为命令大部分时间都在单个聚合的上下文中,那么为什么不让聚合自己处理呢?

    希望对你有所帮助!

    【讨论】:

    • 你是 100% 正确的。我忘记了将标记处理程序作为 bean。也许没有忘记,我只是这个技术堆栈的初学者。感谢您的耐心和准确的回答。
    • 没问题,我很高兴能在这方面提供帮助! :-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-21
    • 2016-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-10
    • 1970-01-01
    相关资源
    最近更新 更多