michaellavelle / spring-data-dynamodb

Simplifies the development of creating an Amazon DynamoDB-based Java data access layer
https://derjust.github.io/spring-data-dynamodb/
Apache License 2.0
169 stars 284 forks source link

Compatibility with spring-data-rest #57

Closed derjust closed 4 years ago

derjust commented 9 years ago

Hi! Thanks for this project!

I tried to integrate it with spring-data-rest to expose my entities. It worked quite well with minor adoptions:

To workaround those two problems, I added to my own ConfigurationBean the following code:

    @Bean
    public DynamoDBMappingContext getMappingContext() {
        DynamoDBMappingContext context = new DynamoDBMappingContext();

        context.getPersistentEntity(MyDynamoDBTable.class);

        return context;
    }

I can't really judge if that is cleaver because that leads to multiple DynamoDBContexts floating around but as they are usually only delegating to another constructor that seems fine to me.

Is there a better way to do it? Can this somehow be incorporated into the library itself so that it is out-of-the-box Spring-Boot compatible?

Used versions:

Selindek commented 9 years ago

I had the same problem although I found a different solution. I manually exposed the existing MappingContext from the DynamoDBRepositoryFactoryBean:

@SuppressWarnings("rawtypes")
@Autowired
private DynamoDBRepositoryFactoryBean dynamoDBRepositoryFactoryBean;

@Bean
public MappingContext<?, ?> getPrivateDynamoDbMappingContext(){
    return (MappingContext<?, ?>)FieldUtils.getProtectedFieldValue("mappingContext", dynamoDBRepositoryFactoryBean);
}

Not the best solution either, but it works. (And if the DynamoDBMappingContext changes by any reason later, it will still work.)

wnagele commented 8 years ago

Without this - PUT requests won't work to update entities. I think this is a bug in the current implementation and needs adressing. I used the solution from @Selindek to work around it as well.