I am trying to setup @SqsListener working but I'm gettin this exception:

 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'simpleMessageListenerContainer' defined in org.springframework.cloud.aws.messaging.config.annotation.SqsConfiguration: Failed to instantiate [org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer]: Factory method 'simpleMessageListenerContainer' threw exception with message: Error creating bean with name 'queueMessageHandler' defined in org.springframework.cloud.aws.messaging.config.annotation.SqsConfiguration: org/springframework/messaging/handler/annotation/support/PayloadArgumentResolver
........
........
    Caused by: java.lang.ClassNotFoundException: org.springframework.messaging.handler.annotation.support.PayloadArgumentResolver
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[na:na]
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[na:na]
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[na:na]
        ... 44 common frames omitted

From my build.gradle:

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'
    implementation 'org.springframework.cloud:spring-cloud-aws-messaging:2.2.6.RELEASE'
    implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'
    implementation 'org.springframework:spring-messaging:6.0.2'

    implementation 'io.awspring.cloud:spring-cloud-starter-aws-messaging:2.4.2'
    implementation 'io.awspring.cloud:spring-cloud-aws-dependencies:2.4.2'
    implementation 'software.amazon.awssdk:sqs:2.18.38'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

I tried different project setups but it all ending with: Caused by: java.lang.ClassNotFoundException: org.springframework.messaging.handler.annotation.support.PayloadArgumentResolver

I think PayloadArgumentResolver was deprecated as of Spring 5.2 in favor of PayloadMethodArgumentResolver.

Is it a bug or a dependencies issue?

3

There are 3 answers

2
kekhuai On

Try downgrade the spring-messaging to version 5.3.24 as a workaround

implementation 'org.springframework:spring-messaging:5.3.24'
0
Erick Jhorman Romero On

Yeah, in my case I had to use PayloadMethodArgumentResolver and it worked.

 implementation('io.awspring.cloud:spring-cloud-aws-core:3.0.2') 
 implementation('io.awspring.cloud:spring-cloud-aws-messaging:2.4.4') 
 implementation('io.awspring.cloud:spring-cloud-starter-aws:2.4.4')

 @Bean  public QueueMessageHandler queueMessageHandler () {
        QueueMessageHandlerFactory queueMsgHandlerFactory = new
 QueueMessageHandlerFactory();
        queueMsgHandlerFactory.setAmazonSqs(amazonSQSAsync());
        QueueMessageHandler queueMessageHandler =
 queueMsgHandlerFactory.createQueueMessageHandler();
        List<HandlerMethodArgumentResolver> list = new ArrayList<>();
        HandlerMethodArgumentResolver resolver = new
 PayloadMethodArgumentResolver(new MappingJackson2MessageConverter());
        list.add(resolver);
        queueMessageHandler.setArgumentResolvers(list);
 
        return queueMessageHandler;     }
2
heroin On

Version 2.x of Spring Cloud AWS does not support Spring Boot 3. Have a look here https://github.com/awspring/spring-cloud-aws. Spring Boot 3 is supported from version 3.x of Spring Cloud AWS, which is at the moment at RC2 stage.