【问题标题】:Spring boot failing to start with Spring Cloud AWS Core dependencySpring Boot 无法从 Spring Cloud AWS Core 依赖项启动
【发布时间】:2018-07-04 00:13:37
【问题描述】:

我正在编写一个从 s3 存储桶访问内容的 spring boot 应用程序,但是当我使用来自 spring 初始化程序的 starter spring-cloud-starter-aws 依赖项时,我得到了一个 NoClassDefFoundError

我在这里错过了一些其他的依赖吗?

以下是我的依赖项。

<dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-amqp</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-aws</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-cassandra</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-integration</artifactId>
    </dependency>

    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>
</dependencies>

我还为spring-cloud-dependencies 定义了dependencyManagement 块,并使用Edgware.SR1 作为我的spring-cloud-version

我的应用程序在启动时失败并出现以下错误。

2018-01-24 12:20:25.642  INFO 1980 --- [           main] utoConfigurationReportLoggingInitializer : 

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2018-01-24 12:20:25.666 ERROR 1980 --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [com.art.productattribution.consumerintegration.ConsumerIntegrationApplication]; nested exception is java.lang.NoClassDefFoundError: com/amazonaws/AmazonClientException
    at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:616) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]

不确定我在这里缺少什么?如果您需要更多详细信息,请告诉我。我使用的spring boot版本是1.5.9.RELEASE

【问题讨论】:

    标签: spring spring-boot spring-cloud spring-cloud-aws


    【解决方案1】:

    您需要包含@alltej 提到的依赖项。如果您在本地运行,还需要在 application.properties 文件中添加以下属性。

    cloud.aws.stack.auto=false
    

    【讨论】:

      【解决方案2】:

      正确的依赖是spring-cloud-aws-context。在您的 pom 文件中添加以下内容(截至 2017 年 11 月 22 日的版本 1.2.2):

      <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-aws-context -->
      <dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-aws-context</artifactId>
          <version>1.2.2.RELEASE</version>
      </dependency>
      

      以下是 Spring Cloud AWS 模块:

      Spring Cloud AWS Core是Spring Cloud AWS的核心模块,为安全和配置设置提供基础服务。开发者不会直接使用这个模块,而是通过其他模块。核心模块支持基于云的环境配置,提供对基于实例的 EC2 元数据和整个应用程序堆栈特定 CloudFormation 元数据的直接访问。

      Spring Cloud AWS Context 通过 Spring 资源加载器抽象提供对简单存储服务的访问。此外,开发人员可以使用简单电子邮件服务和 Spring 邮件抽象来发送电子邮件。此外,开发人员可以使用 Spring 缓存支持和 ElastiCache 缓存服务引入声明式缓存。

      Spring Cloud AWS JDBC 为关系数据库服务提供自动数据源查找和配置,可与 JDBC 或 Spring 的任何其他支持数据访问技术一起使用。

      Spring Cloud AWS Messaging 使开发人员能够使用简单队列服务接收和发送消息以进行点对点通信。简单通知服务的集成支持发布-订阅消息传递。

      参考:http://cloud.spring.io/spring-cloud-aws/spring-cloud-aws.html#_using_amazon_web_services

      【讨论】:

        【解决方案3】:

        似乎在类路径中找不到com.amazonaws.AmazonClientException。我认为您可以在 POM.xml 文件中添加以下依赖项来解决此问题。

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-aws-core</artifactId>
            <version>1.2.2.RELEASE</version>
        </dependency>
        

        【讨论】:

        • 但我的意图是使用 spring-cloud-starter-aws 进行自动配置并从 s3 获取资源。我认为这种更改不会获得自动配置模块。此外,当我使用Edgware.SR1 时,获得的依赖项是 1.2.2.RELEASE。我猜这是spring-cloud-starter-aws 的某种问题。
        • @Wizard AmazonClientException 类在 spring-cloud-aws-core 和 spring-cloud-starter-aws 工件中都找不到。
        • 该类在 AWS Java SDK 中可用。
        • 我认为您可以从自动配置中排除该类以避免此问题。
        猜你喜欢
        • 2021-06-21
        • 2018-05-13
        • 2021-07-24
        • 2018-10-03
        • 2020-03-24
        • 2019-07-13
        • 1970-01-01
        • 2020-10-02
        • 2020-07-08
        相关资源
        最近更新 更多