Spring AWS SQS NoSuchMethodFound异常

时间:2018-01-05 19:29:32

标签: java spring-integration amazon-sqs nosuchmethoderror

我使用Spring Integration SQS出站通道适配器将有效负载发布到SQS。我遇到了一些依赖问题。我得到了例外:

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

以下是我的Gradle依赖项:

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' 

}

这是我的SQS配置:

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

我已经尝试过在互联网上找到的所有建议,但仍然没有运气。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

根据Artem Bilan,修改以下内容:
SI AWS至1.1.0
SC-AWS到1.2.2

SC-AWS获取AWS SDK版本1.11.125。我必须将AWS SQS SDK版本覆盖为1.11.209,如上所述here,以修复依赖项问题。