Dependencies AxoniQ如何将SpringbeanParameterResolveFactory配置为Springbean依赖注入的多参数ResolveFactory的一部分

Dependencies AxoniQ如何将SpringbeanParameterResolveFactory配置为Springbean依赖注入的多参数ResolveFactory的一部分,dependencies,code-injection,axon,Dependencies,Code Injection,Axon,这可能是一个简单的例子,但我尝试了所有axon博客,没有找到如何将SpringbeanParameterResolveFactory配置为多参数ResolveFactory委托列表的一部分的确切配置 ExternalService.java @Component public class ExternalService { public void testcall(){ System.out.println("test operation called&quo

这可能是一个简单的例子,但我尝试了所有axon博客,没有找到如何将SpringbeanParameterResolveFactory配置为多参数ResolveFactory委托列表的一部分的确切配置

ExternalService.java

@Component
public class ExternalService {

    public void testcall(){
        System.out.println("test operation called");
    }
}
pom.xml

<axon.version>4.5</axon.version>

...
...

  <dependency>
            <groupId>org.axonframework</groupId>
            <artifactId>axon-spring-boot-starter</artifactId>
            <version>${axon.version}</version>
        </dependency>


请求帮助。提前感谢。

我写了一篇关于基于集合的一致性验证的文章,并在Github上为此添加了一些代码示例。其中一个示例是使用ParameterResolveFactory。参见第3点,您能否详细说明为什么需要自己配置参数Resolver?通常情况下,这根本不需要,尤其是对于
SpringbeanParameterResolveFactory
,因为它将为您自动配置

只要在应用程序上下文中提供
ExternalService
,通过直接注释它或使用bean创建方法就足够了


如果确实需要添加额外的
参数ResolveFactory
实例,则以下方法应足以自动将它们附加到使用的
多参数ResolveFactory
,而无需您的干扰:

  • ParameterResolveFactory
    的完全限定类名添加到
    resources/META-INF/services
    文件夹中名为
    org.axonframework.messaging.annotation.ParameterResolveFactory
    的文件中。Axon使用服务加载器方法来加载它们,这意味着您可以在需要时附加到它
  • 在Spring环境中,您可以使用
    @Component
    简单地注释您的自定义
    参数ResolveFactory
    ,框架将获取它。简单地说,如果您将它添加到应用程序上下文中,Axon就可以找到它
  • 通过将Axon的
    参数ResolveFactory
    注册为配置API的组件,可以完全覆盖它。为此,您将使用
    Configurer\registerComponent(类、函数)
    方法。请注意,此将要求您提供与前两个选项相应的
    多参数ResolveFactory

外部服务是弹簧组件吗?如果是,这应该是开箱即用的。为@LucasCampos提到的几个细节道歉。我确实同意我确实看到了关于
springbeanParameterResolveFactory
的提及,并尝试了相同的方法,但在
multiparameterResolveFactory
中的解析程序列表中没有连接,在屏幕截图中显示了相同的内容。在repo中添加了完整的代码库,剥离到所需的类。我遵循相同的方法,在bean上使用@Component,我正在命令处理程序中注入该bean,但它没有被注入,并且返回异常,因为Springbeanpf没有在MultiPRF中列出,如屏幕截图所示。不确定我是否缺少任何配置。任何指向工作示例代码的链接都会非常有帮助。很抱歉给您添麻烦@Steven,它工作正常,我这边有一些问题。无需向Kartik道歉,我很高兴听到您发现了问题!如果出现任何其他Axon问题,请知道您可以继续使用SO或专用Axon论坛->谢谢@Yvonne,但我正在寻找
SpringbeanParameterResolveFactory
,如下所述,我从博客上读到的是,它会自动注入
多参数ResolveFactory
,但它不会发生。希望我没有遗漏任何配置。在这里还添加了相同的代码@Kartiknarayanamaringati。看起来Spring设置有问题,并且在处理命令时没有加载组件。如果您查看代码示例,您可以看到在帐户聚合中注入了存储库。该代码没有问题。
  @CommandHandler
    public GiftCard(IssueCmd cmd, ExternalService externalService) {
        externalService.handle();

        logger.debug("handling {}", cmd);
        if (cmd.getAmount() <= 0) {
            throw new IllegalArgumentException("amount <= 0");
        }
        apply(new IssuedEvt(cmd.getId(), cmd.getAmount()));
    }
Caused by: org.axonframework.messaging.annotation.UnsupportedHandlerException: Unable to resolve parameter 1 (ExternalService) in handler public io.axoniq.demo.giftcard.command.GiftCard(io.axoniq.demo.giftcard.api.IssueCmd,io.axoniq.demo.giftcard.service.ExternalService).
    at org.axonframework.messaging.annotation.AnnotatedMessageHandlingMember.<init>(AnnotatedMessageHandlingMember.java:76) ~[axon-messaging-4.5.jar:4.5]
    at org.axonframework.messaging.annotation.AnnotatedMessageHandlingMemberDefinition.lambda$createHandler$0(AnnotatedMessageHandlingMemberDefinition.java:51) ~[axon-messaging-4.5.jar:4.5]
...
...