Skip to content
Advertisement

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

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

Advertisement

Answer

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

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement