Search code examples
javaspring-integrationamazon-sqsnosuchmethoderror

Spring AWS SQS NoSuchMethodFound Exception


I am using Spring Integration SQS Outbound Channel Adapter to publish payload to SQS. I am running into some dependency issue. I am getting the exception:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.aws.outbound.SqsMessageHandler#0': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.integration.aws.outbound.SqsMessageHandler]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.cloud.aws.messaging.core.QueueMessagingTemplate.<init>(Lcom/amazonaws/services/sqs/AmazonSQS;Lorg/springframework/cloud/aws/core/env/ResourceIdResolver;)V
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:279)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1193)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1095)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:109)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:952)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:941)
at com.expedia.dataloader.boot.Application.main(Application.java:15)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.integration.aws.outbound.SqsMessageHandler]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.cloud.aws.messaging.core.QueueMessagingTemplate.<init>(Lcom/amazonaws/services/sqs/AmazonSQS;Lorg/springframework/cloud/aws/core/env/ResourceIdResolver;)V
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:154)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:122)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:271)
... 17 more
Caused by: java.lang.NoSuchMethodError: org.springframework.cloud.aws.messaging.core.QueueMessagingTemplate.<init>(Lcom/amazonaws/services/sqs/AmazonSQS;Lorg/springframework/cloud/aws/core/env/ResourceIdResolver;)V
at org.springframework.integration.aws.outbound.SqsMessageHandler.<init>(SqsMessageHandler.java:56)
at org.springframework.integration.aws.outbound.SqsMessageHandler.<init>(SqsMessageHandler.java:52)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessoava:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:142)
... 19 more

Here are my Gradle dependencies:

dependencies {

providedCompile 'javax.servlet:javax.servlet-api:3.0.1'

compile 'org.springframework.cloud:spring-cloud-aws-context:1.2.2.RELEASE'
compile 'org.springframework.cloud:spring-cloud-aws-core:1.2.2.RELEASE'
compile ("org.springframework.cloud:spring-cloud-aws-messaging:1.2.2.RELEASE") {
    exclude group:'com.amazonaws', module:'aws-java-sdk-sqs' 
}

compile 'org.apache.commons:commons-lang3:3.+'
compile "org.springframework:spring-context:4.3.8.RELEASE"
compile "org.springframework:spring-webmvc:4.3.8.RELEASE"
compile "org.springframework:spring-aop:4.3.8.RELEASE"
compile "org.aspectj:aspectjweaver:1.8.2"
compile 'org.codehaus.castor:castor:1.2'
compile 'com.fasterxml.jackson.core:jackson-databind:2.6.4'
compile 'org.springframework.integration:spring-integration-core:4.3.8.RELEASE'
compile 'org.springframework.integration:spring-integration-http:4.3.8.RELEASE'
compile 'org.springframework.integration:spring-integration-xml:4.3.8.RELEASE'
compile 'org.springframework.integration:spring-integration-amqp:4.3.8.RELEASE'
compile 'org.springframework.integration:spring-integration-stream:4.3.8.RELEASE'
compile 'org.springframework.integration:spring-integration-file:4.3.8.RELEASE'
compile 'org.springframework.integration:spring-integration-java-dsl:1.0.0.RELEASE'
compile group: 'org.springframework.integration', name: 'spring-integration-aws', version: '1.0.0.RELEASE'

compile 'org.projectlombok:lombok:1.14.8'
compile 'joda-time:joda-time:2.+'

compile("org.springframework.boot:spring-boot-starter-web") {
    exclude group: 'org.hibernate'
    exclude group: 'org.springframework'
    exclude group: 'com.fasterxml.jackson.core'
    exclude group: 'org.mockito'
    exclude group: 'junit'
}

compile "ch.qos.logback:logback-classic:1.1.2"    
compile "org.slf4j:jcl-over-slf4j:1.7.7"
compile "org.springframework.boot:spring-boot-starter-tomcat"
compile 'org.apache.httpcomponents:httpclient:4.3.6'
compile 'org.apache.httpcomponents:httpmime:4.3.6'

compile 'com.fasterxml.jackson.core:jackson-databind:2.6.4'

testCompile 'junit:junit:4.+'
testCompile 'org.springframework:spring-test:4.3.8.RELEASE'
testCompile 'org.mockito:mockito-core:1.9.5'
testCompile 'org.apache.commons:commons-io:1.3.2'

jaxb group: 'com.sun.xml.bind', name: 'jaxb-impl', version: '2.2.6'
jaxb group: 'com.sun.xml.bind', name: 'jaxb-xjc', version: '2.2.6'
jaxb group: 'javax.xml', name: 'jaxb-api', version: '2.1.5' 

}

Here is my SQS config:

<aws-messaging:sqs-async-client id="sqs"/>
<int-aws:sqs-outbound-channel-adapter channel="sqsChannel" sqs="sqs" queue="${sqs.queue}"/> 

I have tried all suggestions that I found on Internet, still no luck. Can someone please help?


Solution

  • According to Artem Bilan, modify the following:
    SI AWS to 1.1.0
    SC-AWS to 1.2.2

    SC-AWS fetches AWS SDK version 1.11.125. I had to override AWS SQS SDK version to be 1.11.209 as mentioned here to fix the dependencies issues.