1
votes

I'm trying to move axon from a SimpleCommandBus to a DistributedCommandBus with Eureka for service discovery.

I tried implementing this by going through the documentation provided under axon (https://docs.axoniq.io/reference-guide/extensions/spring-cloud)

When I try starting my application, I'm receiving an error with the message

Error creating bean with name '__axon-annotation-command-handler-bean-post-processor': Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeException

This is how I'm wiring up the distributed command bus:

    public CommandRouter springCloudCommandRouter(DiscoveryClient discoveryClient, Registration localServiceInstance) {
        return SpringCloudCommandRouter.builder()
                .discoveryClient(discoveryClient)
                .routingStrategy(new AnnotationRoutingStrategy(STATIC_KEY))
                .localServiceInstance(localServiceInstance)
                .build();
    }

    @Bean
    public CommandBusConnector springHttpCommandBusConnector(
            @Qualifier("localSegment") CommandBus localSegment,
            RestOperations restOperations,
            Serializer serializer) {
        return SpringHttpCommandBusConnector.builder()
                .localCommandBus(localSegment)
                .restOperations(restOperations)
                .serializer(serializer)
                .build();
    }

    @Primary
    @Bean
    public DistributedCommandBus springCloudDistributedCommandBus(
            CommandRouter commandRouter,
            CommandBusConnector commandBusConnector) {
        return DistributedCommandBus.builder()
                .commandRouter(commandRouter)
                .connector(commandBusConnector)
                .build();
    }



After starting my application with this, I'm receiving the following error message.

2019-07-04T14:02:39.079+05:30 [APP/PROC/WEB/0] [OUT] 2019-07-04 08:32:39.079 WARN 17 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '__axon-annotation-command-handler-bean-post-processor': Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeException
2019-07-04T14:02:39.100+05:30 [APP/PROC/WEB/0] [OUT] Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-07-04T14:02:39.100+05:30 [APP/PROC/WEB/0] [OUT] 2019-07-04 08:32:39.099 INFO 17 --- [ main] ConditionEvaluationReportLoggingListener :
2019-07-04T14:02:39.106+05:30 [APP/PROC/WEB/0] [OUT] 2019-07-04 08:32:39.106 ERROR 17 --- [ main] o.s.boot.SpringApplication : Application run failed
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] ... 23 common frames omitted
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:572)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1331)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.filterPropertyDescriptorsForDependencyCheck(AbstractAutowireCapableBeanFactory.java:1471)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.filterPropertyDescriptorsForDependencyCheck(AbstractAutowireCapableBeanFactory.java:1491)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.BeanWrapperImpl.getPropertyDescriptors(BeanWrapperImpl.java:248)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.BeanWrapperImpl.getCachedIntrospectionResults(BeanWrapperImpl.java:174)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.CachedIntrospectionResults.forClass(CachedIntrospectionResults.java:177)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.CachedIntrospectionResults.<init>(CachedIntrospectionResults.java:294)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.CachedIntrospectionResults.buildGenericTypeAwarePropertyDescriptor(CachedIntrospectionResults.java:359)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.GenericTypeAwarePropertyDescriptor.<init>(GenericTypeAwarePropertyDescriptor.java:106)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at org.springframework.core.GenericTypeResolver.resolveParameterType(GenericTypeResolver.java:61)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at org.springframework.core.ResolvableType.resolveMethodParameter(ResolvableType.java:1297)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at org.springframework.core.ResolvableType.as(ResolvableType.java:443)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at org.springframework.core.ResolvableType.getSuperType(ResolvableType.java:453)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at java.lang.Class.getGenericSuperclass(Class.java:777)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at sun.reflect.generics.repository.ClassRepository.getSuperclass(ClassRepository.java:90)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:138)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at sun.reflect.generics.visitor.Reifier.reifyTypeArguments(Reifier.java:68)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:140)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at sun.reflect.generics.factory.CoreReflectionFactory.makeParameterizedType(CoreReflectionFactory.java:105)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.make(ParameterizedTypeImpl.java:92)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.<init>(ParameterizedTypeImpl.java:51)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.validateConstructorArguments(ParameterizedTypeImpl.java:58)

The dependencies which we are using in our spring boot app is as

<spring-boot.version>2.0.6.RELEASE</spring-boot.version>
<spring.cloud.version>Finchley.RELEASE</spring.cloud.version>
<axon.version>4.0</axon.version>
<axon-spring-boot-starter.version>${axon.version}</axon-spring-boot-starter.version>
 <axon-springcloud.version>4.0</axon-springcloud.version>
 <axon-distributed-commandbus-springcloud.version>3.4.3</axon-distributed-commandbus-springcloud.version>

UPDATE: We tried bumping our axon version to 4.1.2, we are now encountering a 404 error. Stack trace below:

2019-07-17 07:02:48.815 DEBUG [test-app,65da6028861139c5,150e2f6a196c6ce8,false] 19 --- [http-nio-8080-exec-1] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Written [{timestamp=Wed Jul 17 07:02:48 UTC 2019, status=404, error=Not Found, message=No message available, path=/spring-command-bus-connector/command}]

We also tried moving the command router from SpringCloudCommandRouter -> SpringCloudHttpBackupCommandRouter, but to no avail. Any help on this would be greatly appreciated.

1

1 Answers

1
votes

I hope I can help you out with the problem you're encountering.

The __axon-annotation-command-handler-bean-post-processor is a Bean Post Processor Axon Framework introduces to be able to correctly register all Command Handlers you might have set up in your application.

Depending on the version of Axon Framework your utilizing however, this might be dealt with differently.

If you're in an Axon 3.x application, you might be leveraging the @EnableAxon annotation to auto-configure all the Axon niceties for you. When you are however also using the axon-spring-boot-starter dependency to have Spring Boot like auto configuration, you are not required to use the @EnableAxon. It's actually suggested to not use both in this scenario.

To be clearer about this, Axon 4 has dropped the the notion of the @EnableAxon altogether.

Granted, I am sharing this info as you're linking to an Axon 3.x Reference Guide page and hence I am assuming you are using Axon 3. If that's the case, I suggest you either use the @EnableAxon or the axon-spring-boot-starter dependency.

If you are on another version of Axon, I'd like to ask you to update the question to specify the version of the framework and of Spring, and any other important configuration pointers which might help us resolve the problem at hand.

Concluding, I hope this helps you out @Anish!


Update

I think I know what the issue is you're encountering @Anish. You're using Axon Framework 4.0 (which you can by the way update to 4.1.2, pretty sure there's no pain in doing so), but you are still utilizing the axon-distributed-commandbus-springcloud of Axon Framework 3.4.3.

When Axon Framework moved from version 3.x to 4.x, a few modules have been removed from the core repository. Modules like axon-amqp, axon-mongo, but also axon-distributed-commandbus-springcloud. The reasoning behind this is to have independent release cycles for the core and these 'extensions'.

If you want to use an Axon 4 compliant Spring Cloud CommandBus, it is suggested to pull in the Axon Spring Cloud Extension instead.

I assume that as soon as you switch that dependency around, that the issue will be resolved.