I’m trying to initialize SQSClient like this for using it further to call sendMessage():
@PostConstruct
private SqsClient getAWSSQSClient() {
try {
AwsBasicCredentials credentials = AwsBasicCredentials.create(accessKeyId, secretKey);
StaticCredentialsProvider staticCredentialsProvider = StaticCredentialsProvider.create(credentials);
sqsClient = SqsClient.builder().credentialsProvider(staticCredentialsProvider).region(Region.of(region)).build();
logger.info("AmazonSQS initialized successfully");
return sqsClient;
} catch (Exception e) {
logger.error("Exception occurred while initializing AmazonSQS :: ", e);
return null;
}
}
But getting below exception:
Error starting ApplicationContext. To display the condition evaluation report re-run
your application with 'debug' enabled.
2024-Dec-24 12:59:43.198 [main] ERROR o.s.b.SpringApplication - Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'SQSService': Invocation of init method failed
at
org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postPr ocessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:222)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:421)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1767)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:601)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:523)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:325)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:323)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:973)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:946)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:616)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:753)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:455)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:323)
at xx.xx.xx.xx.Application.main(Application.java:53)
Caused by: java.lang.IncompatibleClassChangeError: class software.amazon.awssdk.services.sqs.DefaultSqsBaseClientBuilder overrides final method software.amazon.awssdk.awscore.client.builder.AwsDefaultClientBuilder.setOverrides(Lsoftware/amazon/awssdk/core/client/config/SdkClientConfiguration;)Lsoftware/am
Below is the dependency for SQS:
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>sqs</artifactId>
<version>2.29.37</version>
</dependency>