SpringBoot - Java AWS SDK 2 DynamoDB Enhanced Client 和 devtools 问题

Tor*_*ten 3 java amazon-web-services amazon-dynamodb spring-boot

我正在使用 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;
}
Run Code Online (Sandbox Code Playgroud)

当调用此错误时,它会导致:

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)
Run Code Online (Sandbox Code Playgroud)

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

感谢帮助

tim*_*nen 5

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

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

restart.include.dynamodb=/dynamodb-[\\w\\d-\.]+\.jar
Run Code Online (Sandbox Code Playgroud)

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