Spring aws-cloud SNS http 端点确认订阅无效

Spring aws-cloud SNS http end point confirm subscription not working

在我的 spring 启动 aws-cloud SNS http 端点确认订阅不起作用。当我的应用程序出现错误后出现 SNS 确认时。 错误:

[Request processing failed; nested exception is java.lang.IllegalArgumentException: Invoked method public abstract void org.springframework.cloud.aws.messaging.endpoint.NotificationStatus.confirmSubscription() is no accessor method!] with root cause
    java.lang.IllegalArgumentException: Invoked method public abstract void org.springframework.cloud.aws.messaging.endpoint.NotificationStatus.confirmSubscription() is no accessor method!
        at org.springframework.util.Assert.notNull(Assert.java:115) ~[spring-core-4.2.4.RELEASE.jar!/:4.2.4.RELEASE]
        at org.spring

我的控制器处理程序是:

     @NotificationSubscriptionMapping
        public void handleSubscriptionMessage( NotificationStatus status)   throws IOException {
            //Confirming SNS subscription
            status.confirmSubscription();
        }

我的 Pom 包含以下内容:

     <dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-aws-messaging</artifactId>
          <version>1.0.4.RELEASE</version>
        </dependency>

        <!-- For Spring AWS autoconfiguration-->
        <dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-aws-autoconfigure</artifactId>
          <version>1.0.4.RELEASE</version>
        </dependency>

我遵循了这个link

中的解释

您是否指定了自定义解析器:

<mvc:annotation-driven>
    <mvc:argument-resolvers>
        <ref bean="notificationResolver" />
    </mvc:argument-resolvers>
</mvc:annotation-driven>

<aws-messaging:notification-argument-resolver id="notificationResolver" />

另外,我看不到控制器映射,但是在教程中有一个声明:

Currently it is not possible to define the mapping URL on the method level therefore the RequestMapping must be done at type level and must contain the full path of the endpoint.

为所有在 java 配置之后的人发布这个。请注意,您必须使用实现 HandlerMethodArgumentResolver 的 NotificationMessageHandlerMethodArgumentResolver。

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.aws.messaging.endpoint.NotificationMessageHandlerMethodArgumentResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
@EnableWebMvc
public class MvcConfig extends WebMvcConfigurerAdapter {

    @Autowired
    private NotificationMessageHandlerMethodArgumentResolver notificationResolver;

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
        argumentResolvers.add(notificationMessageHandlerMethodArgumentResolver());
    }

    @Bean
    public NotificationMessageHandlerMethodArgumentResolver notificationMessageHandlerMethodArgumentResolver () {

        return new NotificationMessageHandlerMethodArgumentResolver();
    };

}

我的 Kotlin 配置如下所示,用于配置订阅和消息传递以及取消订阅方法参数解析

        import com.amazonaws.services.sns.AmazonSNS
        import org.springframework.beans.factory.annotation.Autowired
        import org.springframework.cloud.aws.messaging.endpoint.config.NotificationHandlerMethodArgumentResolverConfigurationUtils
        import org.springframework.context.annotation.Configuration
        import org.springframework.web.method.support.HandlerMethodArgumentResolver
        import org.springframework.web.servlet.config.annotation.EnableWebMvc
        import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
        
        @Configuration
        @EnableWebMvc
        class ListenerWebConfiguration : WebMvcConfigurer
        {
          @Autowired
          private lateinit var amazonSNS: AmazonSNS
        
          override fun addArgumentResolvers(argumentResolvers: MutableList<HandlerMethodArgumentResolver>) {
argumentResolvers.add(NotificationHandlerMethodArgumentResolverConfigurationUtils.getNotificationHandlerMethodArgumentResolver(amazonSNS))
          }
        }