Spring Cloud 应用程序无法连接到 AWS Kinesis 'dynamoDBClient' 不能为空

如何解决Spring Cloud 应用程序无法连接到 AWS Kinesis 'dynamoDBClient' 不能为空

由于错误 java.lang.IllegalArgumentException: 'dynamoDBClient' must not be null

//流绑定

EnableBinding(DataStream.class)
public class StreamsConfig {}

//流配置

 public interface DataStream {
 
    String AUDIT_IN = "auditIn";

    @Input(AUDIT_IN)
    SubscribableChannel auditIn();
 }

//流监听器

 @StreamListener(DataStream.AUDIT_IN)
    public void processAudit(finalAuditMessage auditMessage) {
     logger.info("Received audit message : {}",auditMessage);
     MDCUtil.setContext(auditMessage.getTenantId(),null,null);
     persistAuditMessage(auditMessage);
     MDCUtil.clearContext();
 }

应用程序.yaml

  cloud:
    aws:
      stack:
        auto: false
      region:
        static: us-west-2
      credentials:
        useDefaultAwsCredentialsChain: true

  management:
    context-path: /actuator
    security:
      enabled: false
      roles: ADMIN

    endpoint:
      metrics:
        enabled: true
      loggers:
        enabled: true
      health:
        show-details: always

    endpoints:
      web:
        exposure:
          include: "health,metrics,info,loggers"

    metrics:
      export:
        statsd:
          enabled: true
          flavor: telegraf
          host: telegraf-s.cluster-services.svc.cluster.local
          port: 8125
      tags:
        service: audit
        namespace: {{ .Release.Namespace }}

      distribution:
        percentiles:
          http:
            server:
              requests: 0.5,0.9,0.99

        percentiles-histogram:
          http:
            server:
              requests: true

  logging:
    level:
      org.hibernate.sql: DEBUG
      org.hibernate.type.descriptor.sql.BasicBinder: TRACE


  spring:
    application:
      name: audit
    zipkin:
      enabled: false
    cloud:
      stream:
        bindings:
          auditIn:
            content-type: application/json
            destination: ***
            consumer:
              describeStreamRetries: 10
            group: ***

        kinesis:
          binder:
            autocreateStream: true
            autoAddShards: false
            kplKclEnabled: true

      vault:
        token: 00000000-0000-0000-0000-000000000000
        ssl:
          trust-store: ***
          trust-store-password: ***
        generic:
          enabled: false
        host: localhost
        port: 8200
        scheme: https
        connection:
          timeout: 5000
        read-timeout: 15000
        authentication: KUBERNETES
        kubernetes:
          role: owner
          kubernetes-path: kubernetes
          service-account-token-file: token
        kv:
          enabled: false
          backend: kv-v2
          application-name: configuration/MysqL

    jpa:
      open-in-view: false

  audit:
    filter:
      block:
        methods: GET

调试日志

INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Detecting the operating system and cpu architecture
[INFO] ------------------------------------------------------------------------
[INFO] os.detected.name: osx
[INFO] os.detected.arch: x86_64
[INFO] os.detected.classifier: osx-x86_64
[INFO]
[INFO] ---------------------------< com.nile:audit >---------------------------
[INFO] Building audit 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] >>> spring-boot-maven-plugin:2.2.2.RELEASE:run (default-cli) > test-compile @ audit >>>
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ audit ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] copying 1 resource
[INFO] copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ audit ---
[INFO] nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ audit ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] copying 5 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ audit ---
[INFO] nothing to compile - all classes are up to date
[INFO]
[INFO] <<< spring-boot-maven-plugin:2.2.2.RELEASE:run (default-cli) < test-compile @ audit <<<
[INFO]
[INFO]
[INFO] --- spring-boot-maven-plugin:2.2.2.RELEASE:run (default-cli) @ audit ---
[INFO] Attaching agents: []

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__,| / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.2.2.RELEASE)

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils (file:/Users/arvindkgs/.m2/repository/org/springframework/spring-core/5.2.2.RELEASE/spring-core-5.2.2.RELEASE.jar) to method java.lang.classLoader.defineClass(java.lang.String,byte[],int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of org.springframework.cglib.core.ReflectUtils
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2021-02-24 20:40:38,529 ERROR [main] com.nile.cloudutilities.audit.aspect.MethodMap                [] [] - STARTING AUDIT BUILD AT 2021-02-24T15:10:38.524052Z
2021-02-24 20:40:39,984 ERROR [main] com.nile.cloudutilities.audit.aspect.MethodMap                [] [] - FINISHED AUDIT BUILD AT 2021-02-24T15:10:39.984543Z: 3/14/0 (0 mappings)
Running custom WebSecurity
2021-02-24 20:40:52,203 DEBUG [main] org.hibernate.sql                                             [] [] - select loggerconf0_.id as id1_2_,loggerconf0_.create_time as create_t2_2_,loggerconf0_.last_update as last_upd3_2_,loggerconf0_.configuration as configur4_2_,loggerconf0_.service as service5_2_ from logger_configs loggerconf0_ where loggerconf0_.service=?
2021-02-24 20:40:52,219 TRACE [main] org.hibernate.type.descriptor.sql.BasicBinder                 [] [] - binding parameter [1] as [VARCHAR] - [audit]
2021-02-24 20:40:54,068 ERROR [main] org.springframework.cloud.stream.binding.BindingService       [] [] - Failed to create consumer binding; retrying in 30 seconds
org.springframework.cloud.stream.binder.BinderException: Exception thrown while starting consumer:
    at org.springframework.cloud.stream.binder.AbstractMessageChannelBinder.dobindConsumer(AbstractMessageChannelBinder.java:471) ~[spring-cloud-stream-3.0.1.RELEASE.jar:3.0.1.RELEASE]
    at org.springframework.cloud.stream.binder.AbstractMessageChannelBinder.dobindConsumer(AbstractMessageChannelBinder.java:90) ~[spring-cloud-stream-3.0.1.RELEASE.jar:3.0.1.RELEASE]
    at org.springframework.cloud.stream.binder.AbstractBinder.bindConsumer(AbstractBinder.java:143) ~[spring-cloud-stream-3.0.1.RELEASE.jar:3.0.1.RELEASE]
    at org.springframework.cloud.stream.binding.BindingService.dobindConsumer(BindingService.java:169) [spring-cloud-stream-3.0.1.RELEASE.jar:3.0.1.RELEASE]
    at org.springframework.cloud.stream.binding.BindingService.bindConsumer(BindingService.java:126) [spring-cloud-stream-3.0.1.RELEASE.jar:3.0.1.RELEASE]
    at org.springframework.cloud.stream.binding.AbstractBindableProxyFactory.createAndBindInputs(AbstractBindableProxyFactory.java:112) [spring-cloud-stream-3.0.1.RELEASE.jar:3.0.1.RELEASE]
    at org.springframework.cloud.stream.binding.InputBindingLifecycle.doStartWithBindable(InputBindingLifecycle.java:58) [spring-cloud-stream-3.0.1.RELEASE.jar:3.0.1.RELEASE]
    at org.springframework.cloud.stream.binding.AbstractBindingLifecycle$$Lambda$1628/000000000000000000.accept(UnkNown Source) [spring-cloud-stream-3.0.1.RELEASE.jar:3.0.1.RELEASE]
    at java.util.LinkedHashMap$LinkedValues.forEach(LinkedHashMap.java:608) [?:?]
    at org.springframework.cloud.stream.binding.AbstractBindingLifecycle.start(AbstractBindingLifecycle.java:57) [spring-cloud-stream-3.0.1.RELEASE.jar:3.0.1.RELEASE]
    at org.springframework.cloud.stream.binding.InputBindingLifecycle.start(InputBindingLifecycle.java:34) [spring-cloud-stream-3.0.1.RELEASE.jar:3.0.1.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:182) [spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:53) [spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:360) [spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:158) [spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:122) [spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:894) [spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:162) [spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:553) [spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) [spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) [spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE]
    at com.nile.audit.AuditService.main(AuditService.java:60) [classes/:?]
Caused by: java.lang.IllegalArgumentException: 'dynamoDBClient' must not be null.
    at org.springframework.util.Assert.notNull(Assert.java:198) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.springframework.integration.aws.inbound.kinesis.KclMessageDrivenChannelAdapter.<init>(KclMessageDrivenChannelAdapter.java:143) ~[spring-integration-aws-2.3.0.RELEASE.jar:?]
    at org.springframework.cloud.stream.binder.kinesis.KinesisMessageChannelBinder.createKclConsumerEndpoint(KinesisMessageChannelBinder.java:314) ~[spring-cloud-stream-binder-kinesis-2.0.0.RELEASE.jar:2.0.0.RELEASE]
    at org.springframework.cloud.stream.binder.kinesis.KinesisMessageChannelBinder.createConsumerEndpoint(KinesisMessageChannelBinder.java:291) ~[spring-cloud-stream-binder-kinesis-2.0.0.RELEASE.jar:2.0.0.RELEASE]
    at org.springframework.cloud.stream.binder.kinesis.KinesisMessageChannelBinder.createConsumerEndpoint(KinesisMessageChannelBinder.java:89) ~[spring-cloud-stream-binder-kinesis-2.0.0.RELEASE.jar:2.0.0.RELEASE]
    at org.springframework.cloud.stream.binder.AbstractMessageChannelBinder.dobindConsumer(AbstractMessageChannelBinder.java:417) ~[spring-cloud-stream-3.0.1.RELEASE.jar:3.0.1.RELEASE]
    ... 23 more
2021-02-24 20:40:54,167 DEBUG [main] org.hibernate.sql                                             [] [] - select loggerconf0_.id as id1_2_,loggerconf0_.service as service5_2_ from logger_configs loggerconf0_ where loggerconf0_.service=?
2021-02-24 20:40:54,169 TRACE [main] org.hibernate.type.descriptor.sql.BasicBinder                 [] [] - binding parameter [1] as [VARCHAR] - [audit]
^C[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  49.955 s
[INFO] Finished at: 2021-02-24T20:40:58+05:30
[INFO] ------------------------------------------------------------------------
[WARNING] The requested profile "nexus" Could not be activated because it does not exist.

pom.xml - https://drive.google.com/file/d/1kBEj6HqTQS5BgA7StaFZBEKfbLrpgSMR/view?usp=sharing

使用以下 jars

org.springframework.cloud:spring-cloud-stream-binder-kinesis:jar:2.0.0.RELEASE:compile
[INFO] |  +- com.amazonaws:amazon-kinesis-client:jar:1.13.0:compile
[INFO] |  |  +- com.amazonaws:aws-java-sdk-cloudwatch:jar:1.11.655:compile
[INFO] |  |  \- com.google.protobuf:protobuf-java:jar:2.6.1:compile
[INFO] |  +- com.amazonaws:amazon-kinesis-producer:jar:0.14.0:compile
[INFO] |  |  \- commons-lang:commons-lang:jar:2.6:compile
[INFO] |  +- org.springframework.integration:spring-integration-aws:jar:2.3.0.RELEASE:compile
[INFO] |  |  +- org.springframework.cloud:spring-cloud-aws-core:jar:2.2.0.RELEASE:compile
[INFO] |  |  |  +- com.amazonaws:aws-java-sdk-ec2:jar:1.11.415:compile
[INFO] |  |  |  \- com.amazonaws:aws-java-sdk-cloudformation:jar:1.11.415:compile
[INFO] |  |  +- org.springframework.cloud:spring-cloud-aws-messaging:jar:2.2.0.RELEASE:runtime
[INFO] |  |  |  +- com.amazonaws:aws-java-sdk-sns:jar:1.11.415:runtime
[INFO] |  |  |  \- com.amazonaws:aws-java-sdk-sqs:jar:1.11.415:runtime
[INFO] |  |  +- org.springframework.integration:spring-integration-file:jar:5.2.2.RELEASE:runtime
[INFO] |  |  \- org.springframework.integration:spring-integration-http:jar:5.2.2.RELEASE:runtime
[INFO] |  +- org.springframework.cloud:spring-cloud-starter-aws:jar:2.2.0.RELEASE:compile
[INFO] |  |  +- org.springframework.cloud:spring-cloud-aws-context:jar:2.2.0.RELEASE:compile
[INFO] |  |  +- org.springframework.cloud:spring-cloud-aws-autoconfigure:jar:2.2.0.RELEASE:compile
[INFO] |  |  \- javax.activation:javax.activation-api:jar:1.2.0:compile
[INFO] |  +- com.amazonaws:aws-java-sdk-dynamodb:jar:1.11.415:compile
[INFO] |  |  \- com.amazonaws:aws-java-sdk-s3:jar:1.11.415:compile
[INFO] |  |     \- com.amazonaws:aws-java-sdk-kms:jar:1.11.415:compile
[INFO] |  +- com.amazonaws:dynamodb-lock-client:jar:1.1.0:compile
[INFO] |  |  \- org.apache.httpcomponents:httpcore:jar:4.4.12:compile
[INFO] |  +- com.amazonaws:aws-java-sdk-kinesis:jar:1.11.415:compile
[INFO] |  \- com.amazonaws:dynamodb-streams-kinesis-adapter:jar:1.5.0:compile

解决方法

要使用 Spring BOOT 应用程序和 AWS API,请尝试使用适用于 Java V2 API 的官方 AWS 开发工具包(而不是非 Amazon API)。 亚马逊建议从 V1 迁移到 V2

这是一个在 Spring BOOT 应用程序中使用 DynamoDB API V2 的示例。此用例允许用户从简单的 Web 表单提交数据,然后将数据存储在 Amazon DynamoDB 表中。然后它会向您展示如何使用 SNS 来发送短信。此外,这还向您展示了如何在 Spring Boot 应用程序中成功使用 AWS Java V2 API。

编写完成后,这将向您展示如何将 Spring Boot 应用程序部署到云端:

Creating your first AWS Java web application

一旦您获得使用 AWS Java V2 API 的基本 Spring 应用程序,您就可以使用其他服务。

,

我的错。我正在创建一个返回 null 的 DynamoDBClient bean。这个 bean 在 org.springframework.cloud.stream.binder.kinesis.KinesisMessageChannelBinder 中自动装配。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?