Axon-事件处理程序拦截器配置

问题描述 投票:1回答:1

我正在尝试定义“事件处理程序拦截器”,我按照官方文档here上的说明进行操作,但是出现以下错误:

org.springframework.beans.factory.BeanCreationException: error when creating the bean with name 'configureEventProcessing' defined in the resource path class [com / prog / boot / config / EventProcessorConfiguration.class]: invalid factory method 'configureEventProcessing': must have an empty non-return type!

我当前的配置呼叫:

@Configuration
public class EventProcessorConfiguration {

    @Bean
    public void configureEventProcessing(Configurer configurer) {
        configurer.eventProcessing()
                  .registerTrackingEventProcessor("my-tracking-processor")
                  .registerHandlerInterceptor("my-tracking-processor",
                                              configuration -> new MyEventHandlerInterceptor());
    }
}

我的事件MessageHandlerInterceptor实现:

public class MyEventHandlerInterceptor implements MessageHandlerInterceptor<EventMessage<?>> {

    @Override
    public Object handle(UnitOfWork<? extends EventMessage<?>> unitOfWork, InterceptorChain interceptorChain)
            throws Exception {
        EventMessage<?> event = unitOfWork.getMessage();
        String userId = Optional.ofNullable(event.getMetaData().get("userId")).map(uId -> (String) uId)
                .orElseThrow(Exception::new);
        if ("axonUser".equals(userId)) {
            return interceptorChain.proceed();
        }
        return null;
    }
}

我在做什么错?

谢谢!

java spring eventhandler axon
1个回答
1
投票
幸运的是,这个问题很简单(与Axon没有直接关系)。

问题是,您应该在@Autowired方法上使用@Bean而不是configureEventProcessing(Configurer)。方法上的@Bean注释将使其成为“ Bean创建方法”,而您只想绑定到自动配置以“进一步配置”事件处理器。

微调的最后提示,您可以使用EventProcessingConfigurer作为参数,而不是Configurer#eventProcessing调用。这会使您的代码缩短一点。

© www.soinside.com 2019 - 2024. All rights reserved.