SpringBoot - Java AWS SDK 2 DynamoDB Enhanced Client 和 devtools 问题 [英] SpringBoot - Java AWS SDK 2 DynamoDB Enhanced Client and devtools problem
问题描述
我使用的是 Spring Boot 2.17 和 java sdk 以及 dynamodb-enhanced '2.13.8'.
I am using Spring Boot 2.17 and java sdk and dynamodb-enhanced '2.13.8'.
我正在使用增强型客户端调用这样的项目:
I am calling with the enhanced client an item like this:
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 切换为 enabled: false
并没有帮助,但完全删除了有效的开发工具.但这不是一个令人满意的解决方案,因为我想使用 devtools.
Switching the livereload to enabled: false
did not help but completly removing the devtools worked. But this a not statisfying solution since I want to use the devtools.
感谢帮助
推荐答案
Spring Boot DevTools 重启功能是使用两个类加载器实现的.项目由重启类加载器加载,库由基类加载器加载.
Spring Boot DevTools restart functionality is implemented using two classloaders. The project is loaded by the restart classloader and the libraries are loaded by the base classloader.
使用文件 META-INF/spring-devtools.properties
将 DynamoDB jar 移动到 RestartClassloader
:
Use the file META-INF/spring-devtools.properties
to move DynamoDB jars into the RestartClassloader
:
restart.include.dynamodb=/dynamodb-[\\w\\d-\.]+\.jar
这篇关于SpringBoot - Java AWS SDK 2 DynamoDB Enhanced Client 和 devtools 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!