【问题标题】:Spring aws-cloud SNS http end point confirm subscription not workingSpring aws-cloud SNS http端点确认订阅不起作用
【发布时间】:2016-07-02 15:14:48
【问题描述】:

在我的 Spring Boot 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中的说明进行操作

【问题讨论】:

    标签: java spring spring-boot spring-cloud


    【解决方案1】:

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

    <mvc:annotation-driven>
        <mvc:argument-resolvers>
            <ref bean="notificationResolver" />
        </mvc:argument-resolvers>
    </mvc:annotation-driven>
    
    <aws-messaging:notification-argument-resolver id="notificationResolver" />
    

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

    目前无法在方法上定义映射 URL 级别,因此 RequestMapping 必须在类型级别完成,并且必须 包含端点的完整路径。

    【讨论】:

    • 谢谢@m.aibin .... 我正在使用弹簧靴进行此操作。 'spring-cloud-autoconfigure' 会处理这个吗?我在类级别定义的控制器映射。当请求到达 handleSubscriptionMessage 方法时,它工作正常。
    • 我没有指定自定义解析器。如何以 java config 方式执行此操作?因为我正在使用弹簧靴。
    • 嗨。我已经设法使用xml本身添加了这个,因为java配置方式在覆盖请求解析器时存在一些问题。但是现在我在确认请求时遇到了一些错误。我应该在哪里/如何在 spring aws cloud 中配置主题 ARN?不过,我在教程中找不到任何内容。
    • 我的问题得到了解决。解析器工作完美。另一个问题是我需要配置区域。
    【解决方案2】:

    为任何在 java config 之后的人提供这个。请注意,您必须使用实现 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();
        };
    
    }
    

    【讨论】:

      【解决方案3】:

      我的 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))
                }
              }
      

      【讨论】:

        猜你喜欢
        • 2017-04-20
        • 1970-01-01
        • 1970-01-01
        • 2017-12-22
        • 1970-01-01
        • 2012-09-30
        • 2016-04-03
        • 2022-11-20
        • 2023-03-10
        相关资源
        最近更新 更多