7

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 Answer 1

19

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

Sign up to request clarification or add additional context in comments.

1 Comment

I'm using the Spring Boot DevTools restart with spring-cloud-aws-starter-dynamodb 3.4.0. I was getting the ClassCastException, so I excluded the aws sdk like this restart.exclude.aws-sdk=software\\.amazon\\.awssdk\\:.* restart.exclude.aws-dynamodb=.*dynamodb.* But it still does not work. This is my devtools configuration: devtools: restart: enabled: true classloader: enabled: true

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.