Reputation: 2025
In my application I need to use both S3 and SNS of AWS. I was using S3 without problem but now I have added SNS dependency as well as follows:
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.12.141</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-sns</artifactId>
<version>1.12.319</version>
</dependency>
But When I try to subscribe to a topic of SNS:
@GetMapping("/addSubscription/{email}")
public String addSubscription(@PathVariable String email) {
SubscribeRequest request = new SubscribeRequest(TOPIC_ARN, "email", email);
snsClient.subscribe(request); //ERROR COMES HERE
return "Subscription request is pending. To confirm the subscription, check your email : " + email;
}
I get the Error:
2022-10-31 19:56:54.354 ERROR 41464 --- [nio-8080-exec-1] c.a.a.exception.GlobalExceptionHandler : Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: 'void com.amazonaws.http.DefaultErrorResponseHandler.<init>(java.util.Map, com.amazonaws.transform.Unmarshaller)'
I have checked some similar questions and people generally mention the aws sdk version but in their example only 1 service is used but I need both S3 and SNS. How can I use both of them ?
Upvotes: 0
Views: 911
Reputation: 10734
Why are you using the AWS SDK for Java V1. This is not best practice at all. You should be using AWS SDK for Java V2.
It appears you are looking to use SNS with Spring BOOT. If you look at the AWS COde Lib, you will find that exact use case here:
The URL is
To find the most recent code examples for the AWS SDK, always refer to this Code Library.
(Click the Java tab).
UPDATE
I just ran this Spring BOOT app that uses AWS SDK for Java V2 and it works perfectly....
Upvotes: 0