简体   繁体   English

awspring SQS 配置在 Spring 引导项目中不起作用

[英]awspring SQS Configuration not working in Spring Boot Project

We are attempting to move away from spring cloud aws to the new io.awspring.cloud project.我们正在尝试从 spring 云 AWS 迁移到新的io.awspring.cloud项目。 The documentation states:该文档指出:

The AmazonSQSAsync client is automatically created and passed to the template's constructor based on the provided credentials. AmazonSQSAsync 客户端会根据提供的凭证自动创建并传递给模板的构造函数。

I am attempting to run this locally.我正在尝试在本地运行它。 In my pom.xml I have added the dependency:在我的pom.xml我添加了依赖项:

<dependency>
   <groupId>io.awspring.cloud</groupId>
   <artifactId>spring-cloud-aws-messaging</artifactId>
   <version>${spring.cloud.aws}</version> 
</dependency>

And I removed the code to create an AmazonSQSAsync client.我删除了创建 AmazonSQSAsync 客户端的代码。 As per the documentation, I still define a QueueMessagingTemplate根据文档,我仍然定义了一个 QueueMessagingTemplate

import io.awspring.cloud.messaging.core.QueueMessagingTemplate;
import com.amazonaws.services.sqs.AmazonSQSAsync;

@Bean
@Qualifier
public QueueMessagingTemplate queueMessagingTemplateFifoSupport(AmazonSQSAsync amazonSQSAsync,
        ObjectMapper objectMapper) {
    MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
    converter.setSerializedPayloadClass(String.class);
    converter.setObjectMapper(objectMapper);

    QueueMessagingTemplate messagingTemplate = new QueueMessagingTemplate(amazonSQSAsync);
    messagingTemplate.setMessageConverter(converter);

    return messagingTemplate;
}

The package namespace was updated to use io.awspring. package 命名空间已更新为使用 io.awspring。 When running the app I get the error:运行应用程序时出现错误:

No qualifying bean of type 'com.amazonaws.services.sqs.AmazonSQSAsync' available

My belief is that Spring should supply this client automatically.我的信念是 Spring 应该自动提供这个客户端。 Am I missing something?我错过了什么吗?

In my application properties I have defined:在我的应用程序属性中,我定义了:

  • cloud.aws.credentials.access-key cloud.aws.credentials.access-key
  • cloud.aws.credentials.secret-key cloud.aws.credentials.secret-key
  • cloud.aws.region.static cloud.aws.region.static

I was missing a dependency:我缺少一个依赖项:

<dependency>
  <groupId>io.awspring.cloud</groupId>
  <artifactId>spring-cloud-aws-autoconfigure</artifactId>
  <version>${spring.cloud.aws}</version>
</dependency>

which is necessary for automatic creation of default clients这是自动创建默认客户端所必需的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM