如何将 SqsConfiguration 覆盖到 return SimpleMessageListenerContainer 的自定义实现

How to override SqsConfiguration to return custom implementation of SimpleMessageListenerContainer

在我们的 Spring 引导应用程序中,我们使用 Spring Cloud AWS:

从 SQS 队列接收消息。然而,即使队列不可访问(即“(服务:AmazonSQS;状态代码:403;错误代码:AccessDenied”),我们也需要能够启动应用程序。为了为此,我们需要能够覆盖 org.springframework.cloud.aws.messaging.config.annotation.SqsConfiguration class,并提供我们自己的 org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer.

实现

执行此操作的正确方法是什么,并且不会破坏我们现有代码中的自动装配?

您必须为自定义 SimpleMessageListenerContainerFactory 声明 @Bean,但仍然保留 @EnableSql,并且 SqsConfiguration 将与您的自定义一起 @Autowired