SpringBoot – Java AWS SDK 2 DynamoDB Enhanced Client and devtools problem

huangapple go评论82阅读模式
英文:

SpringBoot - Java AWS SDK 2 DynamoDB Enhanced Client and devtools problem

问题

我正在使用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无法转换为class de.xxx.productsapi.db.Product(de.xxx.productsapi.db.Product位于'应用程序'的未命名模块中;de.xxx.productsapi.db.Product位于org.springframework.boot.devtools.restart.classloader.RestartClassLoader的未命名模块中 @19e19c7e的加载器中)
java.lang.ClassCastException: class de.xxx.productsapi.db.Product无法转换为class de.xxx.productsapi.db.Product(de.xxx.productsapi.db.Product位于'应用程序'的未命名模块中;de.xxx.productsapi.db.Product位于org.springframework.boot.devtools.restart.classloader.RestartClassLoader @19e19c7e的未命名模块中的加载器中)


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

感谢帮助
英文:

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;
}

it leads when called to this error:

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)

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.

Thanks for help

答案1

得分: 15

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

英文:

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.

Use the file META-INF/spring-devtools.properties to move DynamoDB jars into the RestartClassloader:

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

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

huangapple
  • 本文由 发表于 2020年5月2日 16:46:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/61556638.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定