【问题标题】:SpringBoot - Java AWS SDK 2 DynamoDB Enhanced Client and devtools problemSpringBoot - Java AWS SDK 2 DynamoDB 增强客户端和开发工具问题
【发布时间】:2020-05-02 08:46:08
【问题描述】:

我正在使用 Spring Boot 2.17 和 java sdk 以及 dynamodb-enhanced '2.13.8'。

我正在与增强客户端调用这样的项目:

public Product readProductById(String id) {
    Key key = Key.builder()
            .partitionValue(id)
            .build();
    Product product =  productTable.getItem(key);
    return product;
}

调用此错误时会导致:

class de.xxx.productsapi.db.Product cannot be cast to class de.xxx.productsapi.db.Product (de.xxx.productsapi.db.Product is in unnamed module of loader 'app'; de.xxx.productsapi.db.Product is in unnamed module of loader org.springframework.boot.devtools.restart.classloader.RestartClassLoader @19e19c7e)
java.lang.ClassCastException: class de.xxx.productsapi.db.Product cannot be cast to class de.xxx.productsapi.db.Product (de.xxx.productsapi.db.Product is in unnamed module of loader 'app'; de.xxx.productsapi.db.Product is in unnamed module of loader org.springframework.boot.devtools.restart.classloader.RestartClassLoader @19e19c7e)

切换 livereload to enabled: false 并没有帮助,但完全删除了 devtools 工作。但这是一个不令人满意的解决方案,因为我想使用 devtools。

感谢您的帮助

【问题讨论】:

    标签: java amazon-web-services spring-boot amazon-dynamodb


    【解决方案1】:

    Spring Boot DevTools 重启功能是使用两个类加载器实现的。项目由重启类加载器加载,库由基类加载器加载。

    使用文件 META-INF/spring-devtools.properties 将 DynamoDB jar 移动到 RestartClassloader

    restart.include.dynamodb=/dynamodb-[\\w\\d-\.]+\.jar
    

    https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#using-boot-devtools-customizing-classload

    【讨论】:

      猜你喜欢
      • 2014-12-05
      • 2014-12-22
      • 2017-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-03
      • 1970-01-01
      相关资源
      最近更新 更多