Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

class <DynamoDBBean>cannot be cast to <DynamoDBBean> class ( <DynamoDBBean> is in unnamed module of loader 'app'; <DynamoDBBean> is in unnamed module of loader org.springframework.boot.devtools.restart.classloader.RestartClassLoader #1043

Closed
peeteko opened this issue Feb 9, 2024 · 3 comments

Comments

@peeteko
Copy link

peeteko commented Feb 9, 2024

Type: Bug

Component:

Describe the bug
When I use Dspring.devtools.restart.enabled=true I have the following ClassCastException when i try to save or load dynamoDBBeans
Only when I disable the devtools restart then it works

I have this problem when I try to the save or load this via dynamoDBTemplate

__dynamoDbTemplate.load(
Key.builder().partitionValue(clientReferenceCode).build(), StatusUpdate.class);

dynamoDbTemplate.save(statusUpdate);__

Exact error message
class be.bpost.isend.epf.partner.service.store.StatusUpdate cannot be cast to class be.bpost.isend.epf.partner.service.store.StatusUpdate (be.bpost.isend.epf.partner.service.store.StatusUpdate is in unnamed module of loader 'app'; be.bpost.isend.epf.partner.service.store.StatusUpdate is in unnamed module of loader org.springframework.boot.devtools.restart.classloader.RestartClassLoader @1e1a4b25)

@DynamoDbBean
public class StatusUpdate {
....

....
}

pom.xml

io.awspring.cloud
spring-cloud-aws-starter-dynamodb



io.awspring.cloud
spring-cloud-aws-dependencies
3.1.0
pom
import


@maciejwalkowiak
Copy link
Contributor

This is known issue in AWS SDK: aws/aws-sdk-java-v2#2604

In our docs we mention that to use devtools, you need to create schema manually: https://docs.awspring.io/spring-cloud-aws/docs/3.1.0/reference/html/index.html#resolving-table-schema

Unfortunately nothing we can do about it.

@peeteko
Copy link
Author

peeteko commented Feb 19, 2024

I have done the following changes. I have removed all aws sdk dynamoDB annotations @DynamoDBBean, @DynamoDBPartitationKey ,... and added TableSchema

After this I can use -Dspring.devtools.restart.enabled=true

private static final TableSchema STATUS_UPDATE_TABLE_SCHEMA =
StaticTableSchema.builder(StatusUpdate.class)
.newItemSupplier(StatusUpdate::new)
.addAttribute(String.class, a -> a.name("clientReferenceCode")
.getter(StatusUpdate::getClientReferenceCode)
.setter(StatusUpdate::setClientReferenceCode)
.tags(primaryPartitionKey()))
.addAttribute(String.class, a -> a.name("status")
.getter(StatusUpdate::getStatus)
.setter(StatusUpdate::setStatus))
.addAttribute(Long.class, a -> a.name("deletionDate")
.getter(StatusUpdate::getDeletionDate)
.setter(StatusUpdate::setDeletionDate))
.build();

@bean
public TableSchema myStatusTableSchema(){
return STATUS_UPDATE_TABLE_SCHEMA;
}

@maciejwalkowiak
Copy link
Contributor

@peeteko and then it worked?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants