Spring Bean Parameter Resolver Factory not Injecting spring components in command handler

Hi Team,

This is a very common issue found ( in many axon forums ) and I am finding myself hard to arrive to the solution. And I apologize, not able to keep up to my anxiety levels and repost the same which I already posted in stackoverflow (dependencies - AxoniQ how to configure SpringBeanParameterResolverFactory as part of MultiParameterResolverFactory for spring beans to dependecy inject - Stack Overflow ) for solution.

Axon Framework- 4.5

I am trying to use the feature to auto inject spring bean into the aggregate, which are marked as @Component, and from the blogs I got to know that, its automatically taken care by SpringBeanParameterResolverFactory, but its not working. I am not sure what else I am missing out.

pom.xml

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

...
...

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

Service to be injected

@Component
public class ExternalService {

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

Aggregate

@Aggregate
@Profile("command")
public class GiftCard {

    private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

    @AggregateIdentifier
    private String giftCardId;
    private int remainingValue;

    @CommandHandler
    public GiftCard(IssueCmd cmd, ExternalService externalService) {
        externalService.testcall();
        logger.debug("handling {}", cmd);
        if (cmd.getAmount() <= 0) {
            throw new IllegalArgumentException("amount <= 0");
        }
        apply(new IssuedEvt(cmd.getId(), cmd.getAmount()));
    }


    @EventSourcingHandler
    public void on(IssuedEvt evt) {
        logger.debug("applying {}", evt);
        giftCardId = evt.getId();
        remainingValue = evt.getAmount();
        logger.debug("new remaining value: {}", remainingValue);
    }


    public GiftCard() {
        // Required by Axon
        logger.debug("Empty constructor invoked");
    }
}
@Component
@Profile("command")
public class GcCommandConfiguration {

    @Bean
    public Repository<GiftCard> giftCardRepository(EventStore eventStore, Cache cache) {
        return EventSourcingRepository.builder(GiftCard.class)
                                      .cache(cache)
                                      .eventStore(eventStore)
                                      .build();
    }

    @Bean
    public Cache cache() {
        return new WeakReferenceCache();
    }
}

Main class


@SpringBootApplication
public class GcApp {

    @Autowired
    private CommandGateway commandGateway;

    public static void main(String[] args) {
        SpringApplication.run(GcApp.class, args).getBean(GcApp.class).run();
    }

    public void run() {
        commandGateway.send(new IssueCmd(UUID.randomUUID().toString(), 10));
    }


}

Below is the exception thrown

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:71) ~[axon-messaging-4.4.8.jar:4.4.8]
	at org.axonframework.messaging.annotation.AnnotatedMessageHandlingMemberDefinition.lambda$createHandler$0(AnnotatedMessageHandlingMemberDefinition.java:51) ~[axon-messaging-4.4.8.jar:4.4.8]
	at java.util.Optional.map(Optional.java:215) ~[na:1.8.0_252]

Request for the help pls.

I think what you are missing is @Autowired annotation on the parameter. Try changing your constructor signature to

public GiftCard(IssueCmd cmd, @Autowired ExternalService externalService) {
...
}

IIRC without @Autowired annotation it would expect to find a component registered with Axon Framework and not a Spring bean.

Hello @milendyankov

Tried the same as below, but still not working. Pushed the same in repo, just in case

Request to share any working example in github.

   @CommandHandler
    public GiftCard(IssueCmd cmd, @Autowired ExternalService externalService) {
        externalService.testcall();
         ....
    }

Just for debugging, pasting all the logs

/home/mnkartik/apps/adoptopenjdk/jdk8u252-b09/bin/java -Dvisualvm.id=739184760490 -javaagent:/home/mnkartik/apps/idea-IC-183.4284.148/lib/idea_rt.jar=36567:/home/mnkartik/apps/idea-IC-183.4284.148/bin -Dfile.encoding=UTF-8 -classpath /home/mnkartik/apps/adoptopenjdk/jdk8u252-b09/jre/lib/charsets.jar:/home/mnkartik/apps/adoptopenjdk/jdk8u252-b09/jre/lib/ext/cldrdata.jar:/home/mnkartik/apps/adoptopenjdk/jdk8u252-b09/jre/lib/ext/dnsns.jar:/home/mnkartik/apps/adoptopenjdk/jdk8u252-b09/jre/lib/ext/jaccess.jar:/home/mnkartik/apps/adoptopenjdk/jdk8u252-b09/jre/lib/ext/localedata.jar:/home/mnkartik/apps/adoptopenjdk/jdk8u252-b09/jre/lib/ext/nashorn.jar:/home/mnkartik/apps/adoptopenjdk/jdk8u252-b09/jre/lib/ext/sunec.jar:/home/mnkartik/apps/adoptopenjdk/jdk8u252-b09/jre/lib/ext/sunjce_provider.jar:/home/mnkartik/apps/adoptopenjdk/jdk8u252-b09/jre/lib/ext/sunpkcs11.jar:/home/mnkartik/apps/adoptopenjdk/jdk8u252-b09/jre/lib/ext/zipfs.jar:/home/mnkartik/apps/adoptopenjdk/jdk8u252-b09/jre/lib/jce.jar:/home/mnkartik/apps/adoptopenjdk/jdk8u252-b09/jre/lib/jsse.jar:/home/mnkartik/apps/adoptopenjdk/jdk8u252-b09/jre/lib/management-agent.jar:/home/mnkartik/apps/adoptopenjdk/jdk8u252-b09/jre/lib/resources.jar:/home/mnkartik/apps/adoptopenjdk/jdk8u252-b09/jre/lib/rt.jar:/home/mnkartik/workspace/axonquickstart-4.5.1/giftcard-demo/target/classes:/home/mnkartik/.m2/repository/org/axonframework/axon-spring-boot-starter/4.5/axon-spring-boot-starter-4.5.jar:/home/mnkartik/.m2/repository/org/axonframework/axon-spring-boot-autoconfigure/4.5/axon-spring-boot-autoconfigure-4.5.jar:/home/mnkartik/.m2/repository/org/axonframework/axon-server-connector/4.5/axon-server-connector-4.5.jar:/home/mnkartik/.m2/repository/io/axoniq/axonserver-connector-java/4.5/axonserver-connector-java-4.5.jar:/home/mnkartik/.m2/repository/io/grpc/grpc-protobuf/1.36.1/grpc-protobuf-1.36.1.jar:/home/mnkartik/.m2/repository/io/grpc/grpc-api/1.36.1/grpc-api-1.36.1.jar:/home/mnkartik/.m2/repository/io/grpc/grpc-context/1.36.1/grpc-context-1.36.1.jar:/home/mnkartik/.m2/repository/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar:/home/mnkartik/.m2/repository/com/google/protobuf/protobuf-java/3.12.0/protobuf-java-3.12.0.jar:/home/mnkartik/.m2/repository/com/google/api/grpc/proto-google-common-protos/2.0.1/proto-google-common-protos-2.0.1.jar:/home/mnkartik/.m2/repository/io/grpc/grpc-protobuf-lite/1.36.1/grpc-protobuf-lite-1.36.1.jar:/home/mnkartik/.m2/repository/com/google/guava/guava/30.0-android/guava-30.0-android.jar:/home/mnkartik/.m2/repository/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1.jar:/home/mnkartik/.m2/repository/com/google/guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar:/home/mnkartik/.m2/repository/org/checkerframework/checker-compat-qual/2.5.5/checker-compat-qual-2.5.5.jar:/home/mnkartik/.m2/repository/com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3.jar:/home/mnkartik/.m2/repository/com/google/errorprone/error_prone_annotations/2.4.0/error_prone_annotations-2.4.0.jar:/home/mnkartik/.m2/repository/org/codehaus/mojo/animal-sniffer-annotations/1.19/animal-sniffer-annotations-1.19.jar:/home/mnkartik/.m2/repository/io/grpc/grpc-stub/1.36.1/grpc-stub-1.36.1.jar:/home/mnkartik/.m2/repository/io/grpc/grpc-netty/1.36.1/grpc-netty-1.36.1.jar:/home/mnkartik/.m2/repository/io/grpc/grpc-core/1.36.1/grpc-core-1.36.1.jar:/home/mnkartik/.m2/repository/com/google/code/gson/gson/2.8.6/gson-2.8.6.jar:/home/mnkartik/.m2/repository/com/google/android/annotations/4.1.1.4/annotations-4.1.1.4.jar:/home/mnkartik/.m2/repository/io/netty/netty-codec-http2/4.1.60.Final/netty-codec-http2-4.1.60.Final.jar:/home/mnkartik/.m2/repository/io/netty/netty-common/4.1.60.Final/netty-common-4.1.60.Final.jar:/home/mnkartik/.m2/repository/io/netty/netty-buffer/4.1.60.Final/netty-buffer-4.1.60.Final.jar:/home/mnkartik/.m2/repository/io/netty/netty-transport/4.1.60.Final/netty-transport-4.1.60.Final.jar:/home/mnkartik/.m2/repository/io/netty/netty-resolver/4.1.60.Final/netty-resolver-4.1.60.Final.jar:/home/mnkartik/.m2/repository/io/netty/netty-codec/4.1.60.Final/netty-codec-4.1.60.Final.jar:/home/mnkartik/.m2/repository/io/netty/netty-handler/4.1.60.Final/netty-handler-4.1.60.Final.jar:/home/mnkartik/.m2/repository/io/netty/netty-codec-http/4.1.60.Final/netty-codec-http-4.1.60.Final.jar:/home/mnkartik/.m2/repository/io/netty/netty-handler-proxy/4.1.60.Final/netty-handler-proxy-4.1.60.Final.jar:/home/mnkartik/.m2/repository/io/netty/netty-codec-socks/4.1.60.Final/netty-codec-socks-4.1.60.Final.jar:/home/mnkartik/.m2/repository/io/perfmark/perfmark-api/0.23.0/perfmark-api-0.23.0.jar:/home/mnkartik/.m2/repository/io/netty/netty-tcnative-boringssl-static/2.0.36.Final/netty-tcnative-boringssl-static-2.0.36.Final.jar:/home/mnkartik/.m2/repository/org/axonframework/axon-spring/4.5/axon-spring-4.5.jar:/home/mnkartik/.m2/repository/org/axonframework/axon-configuration/4.5/axon-configuration-4.5.jar:/home/mnkartik/.m2/repository/org/axonframework/axon-disruptor/4.5/axon-disruptor-4.5.jar:/home/mnkartik/.m2/repository/com/lmax/disruptor/3.4.2/disruptor-3.4.2.jar:/home/mnkartik/.m2/repository/org/axonframework/axon-eventsourcing/4.5/axon-eventsourcing-4.5.jar:/home/mnkartik/.m2/repository/org/axonframework/axon-modelling/4.5/axon-modelling-4.5.jar:/home/mnkartik/.m2/repository/org/axonframework/axon-messaging/4.5/axon-messaging-4.5.jar:/home/mnkartik/.m2/repository/com/thoughtworks/xstream/xstream/1.4.16/xstream-1.4.16.jar:/home/mnkartik/.m2/repository/io/github/x-stream/mxparser/1.2.1/mxparser-1.2.1.jar:/home/mnkartik/.m2/repository/xmlpull/xmlpull/1.1.3.1/xmlpull-1.1.3.1.jar:/home/mnkartik/.m2/repository/org/springframework/boot/spring-boot-starter-web/2.4.4/spring-boot-starter-web-2.4.4.jar:/home/mnkartik/.m2/repository/org/springframework/boot/spring-boot-starter/2.4.4/spring-boot-starter-2.4.4.jar:/home/mnkartik/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/2.4.4/spring-boot-autoconfigure-2.4.4.jar:/home/mnkartik/.m2/repository/org/springframework/boot/spring-boot-starter-logging/2.4.4/spring-boot-starter-logging-2.4.4.jar:/home/mnkartik/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar:/home/mnkartik/.m2/repository/ch/qos/logback/logback-core/1.2.3/logback-core-1.2.3.jar:/home/mnkartik/.m2/repository/org/apache/logging/log4j/log4j-to-slf4j/2.13.3/log4j-to-slf4j-2.13.3.jar:/home/mnkartik/.m2/repository/org/apache/logging/log4j/log4j-api/2.13.3/log4j-api-2.13.3.jar:/home/mnkartik/.m2/repository/org/slf4j/jul-to-slf4j/1.7.30/jul-to-slf4j-1.7.30.jar:/home/mnkartik/.m2/repository/jakarta/annotation/jakarta.annotation-api/1.3.5/jakarta.annotation-api-1.3.5.jar:/home/mnkartik/.m2/repository/org/springframework/spring-core/5.3.5/spring-core-5.3.5.jar:/home/mnkartik/.m2/repository/org/springframework/spring-jcl/5.3.5/spring-jcl-5.3.5.jar:/home/mnkartik/.m2/repository/org/yaml/snakeyaml/1.27/snakeyaml-1.27.jar:/home/mnkartik/.m2/repository/org/springframework/boot/spring-boot-starter-json/2.4.4/spring-boot-starter-json-2.4.4.jar:/home/mnkartik/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.11.4/jackson-databind-2.11.4.jar:/home/mnkartik/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.11.4/jackson-annotations-2.11.4.jar:/home/mnkartik/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.11.4/jackson-core-2.11.4.jar:/home/mnkartik/.m2/repository/com/fasterxml/jackson/datatype/jackson-datatype-jdk8/2.11.4/jackson-datatype-jdk8-2.11.4.jar:/home/mnkartik/.m2/repository/com/fasterxml/jackson/datatype/jackson-datatype-jsr310/2.11.4/jackson-datatype-jsr310-2.11.4.jar:/home/mnkartik/.m2/repository/com/fasterxml/jackson/module/jackson-module-parameter-names/2.11.4/jackson-module-parameter-names-2.11.4.jar:/home/mnkartik/.m2/repository/org/springframework/boot/spring-boot-starter-tomcat/2.4.4/spring-boot-starter-tomcat-2.4.4.jar:/home/mnkartik/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.44/tomcat-embed-core-9.0.44.jar:/home/mnkartik/.m2/repository/org/glassfish/jakarta.el/3.0.3/jakarta.el-3.0.3.jar:/home/mnkartik/.m2/repository/org/apache/tomcat/embed/tomcat-embed-websocket/9.0.44/tomcat-embed-websocket-9.0.44.jar:/home/mnkartik/.m2/repository/org/springframework/spring-web/5.3.5/spring-web-5.3.5.jar:/home/mnkartik/.m2/repository/org/springframework/spring-beans/5.3.5/spring-beans-5.3.5.jar:/home/mnkartik/.m2/repository/org/springframework/spring-webmvc/5.3.5/spring-webmvc-5.3.5.jar:/home/mnkartik/.m2/repository/org/springframework/spring-aop/5.3.5/spring-aop-5.3.5.jar:/home/mnkartik/.m2/repository/org/springframework/spring-context/5.3.5/spring-context-5.3.5.jar:/home/mnkartik/.m2/repository/org/springframework/spring-expression/5.3.5/spring-expression-5.3.5.jar:/home/mnkartik/.m2/repository/org/springframework/boot/spring-boot-starter-data-jpa/2.4.4/spring-boot-starter-data-jpa-2.4.4.jar:/home/mnkartik/.m2/repository/org/springframework/boot/spring-boot-starter-aop/2.4.4/spring-boot-starter-aop-2.4.4.jar:/home/mnkartik/.m2/repository/org/aspectj/aspectjweaver/1.9.6/aspectjweaver-1.9.6.jar:/home/mnkartik/.m2/repository/org/springframework/boot/spring-boot-starter-jdbc/2.4.4/spring-boot-starter-jdbc-2.4.4.jar:/home/mnkartik/.m2/repository/com/zaxxer/HikariCP/3.4.5/HikariCP-3.4.5.jar:/home/mnkartik/.m2/repository/org/springframework/spring-jdbc/5.3.5/spring-jdbc-5.3.5.jar:/home/mnkartik/.m2/repository/jakarta/transaction/jakarta.transaction-api/1.3.3/jakarta.transaction-api-1.3.3.jar:/home/mnkartik/.m2/repository/jakarta/persistence/jakarta.persistence-api/2.2.3/jakarta.persistence-api-2.2.3.jar:/home/mnkartik/.m2/repository/org/hibernate/hibernate-core/5.4.29.Final/hibernate-core-5.4.29.Final.jar:/home/mnkartik/.m2/repository/org/jboss/logging/jboss-logging/3.4.1.Final/jboss-logging-3.4.1.Final.jar:/home/mnkartik/.m2/repository/org/javassist/javassist/3.27.0-GA/javassist-3.27.0-GA.jar:/home/mnkartik/.m2/repository/net/bytebuddy/byte-buddy/1.10.22/byte-buddy-1.10.22.jar:/home/mnkartik/.m2/repository/antlr/antlr/2.7.7/antlr-2.7.7.jar:/home/mnkartik/.m2/repository/org/jboss/jandex/2.2.3.Final/jandex-2.2.3.Final.jar:/home/mnkartik/.m2/repository/com/fasterxml/classmate/1.5.1/classmate-1.5.1.jar:/home/mnkartik/.m2/repository/org/dom4j/dom4j/2.1.3/dom4j-2.1.3.jar:/home/mnkartik/.m2/repository/org/hibernate/common/hibernate-commons-annotations/5.1.2.Final/hibernate-commons-annotations-5.1.2.Final.jar:/home/mnkartik/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.3/jaxb-runtime-2.3.3.jar:/home/mnkartik/.m2/repository/jakarta/xml/bind/jakarta.xml.bind-api/2.3.3/jakarta.xml.bind-api-2.3.3.jar:/home/mnkartik/.m2/repository/org/glassfish/jaxb/txw2/2.3.3/txw2-2.3.3.jar:/home/mnkartik/.m2/repository/com/sun/istack/istack-commons-runtime/3.0.11/istack-commons-runtime-3.0.11.jar:/home/mnkartik/.m2/repository/com/sun/activation/jakarta.activation/1.2.2/jakarta.activation-1.2.2.jar:/home/mnkartik/.m2/repository/org/springframework/data/spring-data-jpa/2.4.6/spring-data-jpa-2.4.6.jar:/home/mnkartik/.m2/repository/org/springframework/data/spring-data-commons/2.4.6/spring-data-commons-2.4.6.jar:/home/mnkartik/.m2/repository/org/springframework/spring-orm/5.3.5/spring-orm-5.3.5.jar:/home/mnkartik/.m2/repository/org/springframework/spring-tx/5.3.5/spring-tx-5.3.5.jar:/home/mnkartik/.m2/repository/org/springframework/spring-aspects/5.3.5/spring-aspects-5.3.5.jar:/home/mnkartik/.m2/repository/com/h2database/h2/1.4.200/h2-1.4.200.jar:/home/mnkartik/.m2/repository/org/projectlombok/lombok/1.18.20/lombok-1.18.20.jar:/home/mnkartik/.m2/repository/io/projectreactor/reactor-core/3.4.4/reactor-core-3.4.4.jar:/home/mnkartik/.m2/repository/org/reactivestreams/reactive-streams/1.0.3/reactive-streams-1.0.3.jar:/home/mnkartik/.m2/repository/org/slf4j/slf4j-ext/1.7.30/slf4j-ext-1.7.30.jar:/home/mnkartik/.m2/repository/org/slf4j/slf4j-api/1.7.30/slf4j-api-1.7.30.jar:/home/mnkartik/.m2/repository/org/axonframework/axon-micrometer/4.5/axon-micrometer-4.5.jar:/home/mnkartik/.m2/repository/io/micrometer/micrometer-core/1.6.5/micrometer-core-1.6.5.jar:/home/mnkartik/.m2/repository/org/hdrhistogram/HdrHistogram/2.1.12/HdrHistogram-2.1.12.jar:/home/mnkartik/.m2/repository/org/latencyutils/LatencyUtils/2.0.3/LatencyUtils-2.0.3.jar:/home/mnkartik/.m2/repository/org/springframework/boot/spring-boot-starter-actuator/2.4.4/spring-boot-starter-actuator-2.4.4.jar:/home/mnkartik/.m2/repository/org/springframework/boot/spring-boot-actuator-autoconfigure/2.4.4/spring-boot-actuator-autoconfigure-2.4.4.jar:/home/mnkartik/.m2/repository/org/springframework/boot/spring-boot-actuator/2.4.4/spring-boot-actuator-2.4.4.jar:/home/mnkartik/.m2/repository/org/springframework/boot/spring-boot/2.4.4/spring-boot-2.4.4.jar io.axoniq.demo.giftcard.GcApp

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.4.4)

2021-04-24 03:31:17.398  INFO 10682 --- [           main] io.axoniq.demo.giftcard.GcApp            : Starting GcApp using Java 1.8.0_252 on mnk with PID 10682 (/home/mnkartik/workspace/axonquickstart-4.5.1/giftcard-demo/target/classes started by mnkartik in /home/mnkartik/workspace/stockapplication)
2021-04-24 03:31:17.410 DEBUG 10682 --- [           main] io.axoniq.demo.giftcard.GcApp            : Running with Spring Boot v2.4.4, Spring v5.3.5
2021-04-24 03:31:17.410  INFO 10682 --- [           main] io.axoniq.demo.giftcard.GcApp            : The following profiles are active: command,query,gui
2021-04-24 03:31:20.145  INFO 10682 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2021-04-24 03:31:20.187  INFO 10682 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 30 ms. Found 0 JPA repository interfaces.
2021-04-24 03:31:20.289  INFO 10682 --- [           main] o.s.c.a.ConfigurationClassPostProcessor  : Cannot enhance @Configuration bean definition 'org.axonframework.springboot.autoconfig.EventProcessingAutoConfiguration' since its singleton instance has been created too early. The typical cause is a non-static @Bean method with a BeanDefinitionRegistryPostProcessor return type: Consider declaring such methods as 'static'.
2021-04-24 03:31:20.493  INFO 10682 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean '(inner bean)#438bad7c#32' of type [org.axonframework.spring.config.annotation.SpringContextParameterResolverFactoryBuilder$ClasspathParameterResolverFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-04-24 03:31:20.493  INFO 10682 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean '(inner bean)#438bad7c#32' of type [org.axonframework.messaging.annotation.MultiParameterResolverFactory] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-04-24 03:31:20.497  INFO 10682 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean '(inner bean)#71ea1fda#32' of type [org.axonframework.spring.config.annotation.SpringBeanDependencyResolverFactory] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-04-24 03:31:20.498  INFO 10682 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean '(inner bean)#6aba5d30' of type [org.axonframework.spring.config.annotation.SpringBeanParameterResolverFactory] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-04-24 03:31:20.687  INFO 10682 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean '__axon-parameter-resolver-factory' of type [org.axonframework.spring.config.ApplicationContextLookupParameterResolverFactory] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-04-24 03:31:20.687  INFO 10682 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean '__axon-parameter-resolver-factory' of type [org.axonframework.messaging.annotation.MultiParameterResolverFactory] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-04-24 03:31:20.700  INFO 10682 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean '(inner bean)#7a8406c2' of type [org.axonframework.spring.config.annotation.SpringHandlerDefinitionBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-04-24 03:31:20.705  INFO 10682 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean '(inner bean)#7a8406c2' of type [org.axonframework.messaging.annotation.MultiHandlerDefinition] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-04-24 03:31:20.707  INFO 10682 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean '(inner bean)#2dd2e270' of type [org.axonframework.spring.config.annotation.SpringHandlerEnhancerDefinitionBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-04-24 03:31:20.708  INFO 10682 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean '(inner bean)#2dd2e270' of type [org.axonframework.messaging.annotation.MultiHandlerEnhancerDefinition] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-04-24 03:31:20.710  INFO 10682 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean '__axon-handler-definition' of type [org.axonframework.messaging.annotation.MultiHandlerDefinition] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-04-24 03:31:21.060  INFO 10682 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2021-04-24 03:31:21.080  INFO 10682 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-04-24 03:31:21.080  INFO 10682 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.44]
2021-04-24 03:31:21.267  INFO 10682 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-04-24 03:31:21.268  INFO 10682 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 3700 ms
2021-04-24 03:31:21.713  INFO 10682 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2021-04-24 03:31:21.785  INFO 10682 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 5.4.29.Final
2021-04-24 03:31:21.988  INFO 10682 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2021-04-24 03:31:22.145  INFO 10682 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2021-04-24 03:31:25.802  INFO 10682 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2021-04-24 03:31:25.838  INFO 10682 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2021-04-24 03:31:26.833  INFO 10682 --- [           main] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2021-04-24 03:31:26.848  INFO 10682 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2021-04-24 03:31:27.362  INFO 10682 --- [           main] o.a.serialization.ChainingConverter      : ContentTypeConverter of type [class org.axonframework.serialization.xml.XomToStringConverter] is ignored. It seems to rely on a class that is not available in the class loader: nu/xom/Document
2021-04-24 03:31:27.363  INFO 10682 --- [           main] o.a.serialization.ChainingConverter      : ContentTypeConverter of type [class org.axonframework.serialization.xml.InputStreamToXomConverter] is ignored. It seems to rely on a class that is not available in the class loader: nu/xom/ParsingException
2021-04-24 03:31:27.454  WARN 10682 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'giftCardRepository' defined in class path resource [io/axoniq/demo/giftcard/command/GcCommandConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.axonframework.modelling.command.Repository]: Factory method 'giftCardRepository' threw exception; nested exception is 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).
2021-04-24 03:31:27.456  INFO 10682 --- [           main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2021-04-24 03:31:27.460  INFO 10682 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2021-04-24 03:31:27.465  INFO 10682 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.
2021-04-24 03:31:27.469  INFO 10682 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2021-04-24 03:31:27.489  INFO 10682 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-04-24 03:31:27.511 ERROR 10682 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'giftCardRepository' defined in class path resource [io/axoniq/demo/giftcard/command/GcCommandConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.axonframework.modelling.command.Repository]: Factory method 'giftCardRepository' threw exception; nested exception is 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.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) ~[spring-beans-5.3.5.jar:5.3.5]
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:638) ~[spring-beans-5.3.5.jar:5.3.5]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1334) ~[spring-beans-5.3.5.jar:5.3.5]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177) ~[spring-beans-5.3.5.jar:5.3.5]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564) ~[spring-beans-5.3.5.jar:5.3.5]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524) ~[spring-beans-5.3.5.jar:5.3.5]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.5.jar:5.3.5]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.5.jar:5.3.5]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.5.jar:5.3.5]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.5.jar:5.3.5]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944) ~[spring-beans-5.3.5.jar:5.3.5]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.5.jar:5.3.5]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.5.jar:5.3.5]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144) ~[spring-boot-2.4.4.jar:2.4.4]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:769) [spring-boot-2.4.4.jar:2.4.4]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761) [spring-boot-2.4.4.jar:2.4.4]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:426) [spring-boot-2.4.4.jar:2.4.4]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:326) [spring-boot-2.4.4.jar:2.4.4]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1313) [spring-boot-2.4.4.jar:2.4.4]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1302) [spring-boot-2.4.4.jar:2.4.4]
	at io.axoniq.demo.giftcard.GcApp.main(GcApp.java:19) [classes/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.axonframework.modelling.command.Repository]: Factory method 'giftCardRepository' threw exception; nested exception is 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.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.5.jar:5.3.5]
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.5.jar:5.3.5]
	... 20 common frames omitted
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]
	at java.util.Optional.map(Optional.java:215) ~[na:1.8.0_252]
	at org.axonframework.messaging.annotation.AnnotatedMessageHandlingMemberDefinition.createHandler(AnnotatedMessageHandlingMemberDefinition.java:48) ~[axon-messaging-4.5.jar:4.5]
	at org.axonframework.messaging.annotation.MultiHandlerDefinition.createHandler(MultiHandlerDefinition.java:182) ~[axon-messaging-4.5.jar:4.5]
	at org.axonframework.messaging.annotation.AnnotatedHandlerInspector.initializeMessageHandlers(AnnotatedHandlerInspector.java:207) ~[axon-messaging-4.5.jar:4.5]
	at org.axonframework.messaging.annotation.AnnotatedHandlerInspector.initialize(AnnotatedHandlerInspector.java:194) ~[axon-messaging-4.5.jar:4.5]
	at org.axonframework.messaging.annotation.AnnotatedHandlerInspector.createInspector(AnnotatedHandlerInspector.java:150) ~[axon-messaging-4.5.jar:4.5]
	at org.axonframework.messaging.annotation.AnnotatedHandlerInspector.inspectType(AnnotatedHandlerInspector.java:135) ~[axon-messaging-4.5.jar:4.5]
	at org.axonframework.modelling.command.inspection.AnnotatedAggregateMetaModelFactory.createModel(AnnotatedAggregateMetaModelFactory.java:194) ~[axon-modelling-4.5.jar:4.5]
	at org.axonframework.modelling.command.inspection.AnnotatedAggregateMetaModelFactory.createModel(AnnotatedAggregateMetaModelFactory.java:73) ~[axon-modelling-4.5.jar:4.5]
	at org.axonframework.modelling.command.inspection.AggregateMetaModelFactory.createModel(AggregateMetaModelFactory.java:36) ~[axon-modelling-4.5.jar:4.5]
	at org.axonframework.modelling.command.inspection.AnnotatedAggregateMetaModelFactory.inspectAggregate(AnnotatedAggregateMetaModelFactory.java:89) ~[axon-modelling-4.5.jar:4.5]
	at org.axonframework.modelling.command.AbstractRepository$Builder.inspectAggregateModel(AbstractRepository.java:435) ~[axon-modelling-4.5.jar:4.5]
	at org.axonframework.modelling.command.AbstractRepository$Builder.buildAggregateModel(AbstractRepository.java:427) ~[axon-modelling-4.5.jar:4.5]
	at org.axonframework.modelling.command.AbstractRepository.<init>(AbstractRepository.java:74) ~[axon-modelling-4.5.jar:4.5]
	at org.axonframework.modelling.command.LockingRepository.<init>(LockingRepository.java:75) ~[axon-modelling-4.5.jar:4.5]
	at org.axonframework.eventsourcing.EventSourcingRepository.<init>(EventSourcingRepository.java:79) ~[axon-eventsourcing-4.5.jar:4.5]
	at org.axonframework.eventsourcing.CachingEventSourcingRepository.<init>(CachingEventSourcingRepository.java:69) ~[axon-eventsourcing-4.5.jar:4.5]
	at org.axonframework.eventsourcing.EventSourcingRepository$Builder.build(EventSourcingRepository.java:360) ~[axon-eventsourcing-4.5.jar:4.5]
	at io.axoniq.demo.giftcard.command.GcCommandConfiguration.giftCardRepository(GcCommandConfiguration.java:21) ~[classes/:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_252]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_252]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_252]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_252]
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.5.jar:5.3.5]
	... 21 common frames omitted


Process finished with exit code 1

Sorry for the trouble @milendyankov and team, its working, there must have been some issue from my side.
With or without also the @Autowired applied inside the handler its working and getting resloved.

Thank you for the efforts.