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

Compatibility with spring-data-rest #15

Closed
derjust opened this issue Jan 25, 2016 · 7 comments
Closed

Compatibility with spring-data-rest #15

derjust opened this issue Jan 25, 2016 · 7 comments

Comments

@derjust
Copy link
Owner

derjust commented Jan 25, 2016

Migration of michaellavelle#57

@hmcmanus
Copy link

Great project. Vote +1 for this feature.

@fjvieira
Copy link

I managed a way of doing it. It is already deployed in a project I am working currently. I will put it in a pull request.

@gvasselai
Copy link

Hi @fjvieira , have you had a chance to submit the pull request? I'm also facing this problem with version 4.4.1.

@fjvieira
Copy link

fjvieira commented Mar 6, 2017

Hey, @gvasselai , sorry to be late.

I provided an example project with it.

You can check it on https://github.com/affinitas/DynamoDBExample

Regards.

@gauravbrills
Copy link

Thanks @fjvieira you rock , that solved the issue with resolutions for post requests ,specially via the HAL browser .

@boothen
Copy link

boothen commented Jun 8, 2018

The issue is because Spring Data Rest uses PersistentEntityResourceAssembler when rendering the resource. PersistentEntityResourceAssembler should use the DynamoDBMappingContext, however as this hasn't been constructed as a Spring Bean, it isn't picked up.

Simply declaring a DynamoDBMappingContext Spring Bean doesn't work either as it needs to be initialised. @fjvieira example project initialises DynamoDBMappingContext, however it means 2 separate instances of DynamoDBMappingContext are created.

If we expose the ability to inject a DynamoDBMappingContext bean into DynamoDBRepositoryConfigExtension we can avoid the initialisation code in the Application Configuration. Also, it'll mean a single instance of DynamoDBMappingContext will be used.

I've created a PR to allow the DynamoDBMappingContext to be declared as a Spring Bean and initialised correctly.

#168

If the PR is accepted, the Application Configuration for a Spring Data Rest service would be as follows:

@Configuration
@EnableDynamoDBRepositories(basePackages = "com.acme.repositories", mappingContextRef = "dynamoDBMappingContext")
public class DynamoDBConfig {

	@Value("${amazon.dynamodb.endpoint}")
	private String amazonDynamoDBEndpoint;

	@Value("${amazon.aws.accesskey}")
	private String amazonAWSAccessKey;

	@Value("${amazon.aws.secretkey}")
	private String amazonAWSSecretKey;

	@Bean
	public AmazonDynamoDB amazonDynamoDB(AWSCredentials amazonAWSCredentials) {
		AmazonDynamoDB amazonDynamoDB = new AmazonDynamoDBClient(amazonAWSCredentials);

		if (StringUtils.isNotEmpty(amazonDynamoDBEndpoint)) {
			amazonDynamoDB.setEndpoint(amazonDynamoDBEndpoint);
		}
		return amazonDynamoDB;
	}

	@Bean
	public AWSCredentials amazonAWSCredentials() {
	    // Or use an AWSCredentialsProvider/AWSCredentialsProviderChain
		return new BasicAWSCredentials(amazonAWSAccessKey, amazonAWSSecretKey);
	}

        @Bean
        public DynamoDBMappingContext dynamoDBMappingContext() {
               return new DynamoDBMappingContext();
        }
}

@derjust derjust added this to the v5.0.3 milestone Jun 12, 2018
@derjust
Copy link
Owner Author

derjust commented Jun 12, 2018

Thanks to @boothen and his PR #168 this was merged into master and will be part of the upcoming 5.0.3 release.
Documentation to be found here in the wiki.

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

No branches or pull requests

6 participants