itswuanran / enode

DDD 框架
MIT License
207 stars 55 forks source link

CommandHandlerProvider 无法加载 返回值为 IApplicationMessage的 Subscribe #87

Closed 654894017 closed 4 years ago

654894017 commented 4 years ago

BankAccountCommandHandler类handleAsync(ValidateAccountCommand command) 无法进入,控制台抛出以下异常:

2020-10-14 22:15:02.185 ERROR 18920 --- [ssageExecutor-3] o.e.c.i.DefaultProcessingCommandHandler : No command handler found of command. commandType:org.enodeframework.samples.commands.bank.ValidateAccountCommand, commandId:5f870324fab00c48f072b366,

断点发现 commandHandlerProvider.handlerDict 中没有加载ValidateAccountCommand hanler

654894017 commented 4 years ago

找到问题 public IApplicationMessage handleAsync(ICommandContext context,ValidateAccountCommand command) 方法需要增加ICommandContext context这个参数不然,commandHandlerProvider.handlerDict 设置完成后,不知道哪里又置空了 o(╥﹏╥)o

itswuanran commented 4 years ago

这里实现限定了方法参数类型,已修改

    protected boolean isHandleMethodMatch(Method method) {
        if (method.getParameterTypes().length != 2) {
            return false;
        }
        if (!ICommandContext.class.equals(method.getParameterTypes()[0])) {
            return false;
        }
        if (ICommand.class.equals(method.getParameterTypes()[1])) {
            return false;
        }
        if (!ICommand.class.isAssignableFrom(method.getParameterTypes()[1])) {
            return false;
        }
        return isMethodAnnotationSubscribe(method);
    }