Skip to content

derjust/spring-data-dynamodb-examples

Repository files navigation

📚 Spring Data DynamoDB Examples

Examples for Spring-Data-DynamoDB available at github.com/derjust/spring-data-dynamodb

Please also check the 📖 Wiki

The following examples exist and how they can be executed

🚀 Simple Repository

This example show the most basic usage also referenced by the README.md of the main project.

Further explanation can be found

📗 Multi Repository

This example shows how to use multiple Spring Data repository types to access different storage backend.

In this example DynamoDB and MySQL is used.

Further explanation can be found

📜 Code sample

The respective repository providers must be informed which interface to take care of. In a @Configurable bean the interfaces have to be assigned via include/exclude filters:

@SpringBootApplication
@EnableJpaRepositories(
  includeFilters = {
    @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {
      CustomerRepository.class}
  )}
)
@EnableDynamoDBRepositories(
  includeFilters = {
    @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {
      DeviceRepository.class}
  )}
)
@Configuration
public class Application {

📕 Custom repository methods

This example shows how to use custom methods as part of Spring Data repository interfaces to implement custom logic.

Further explanation can be found

📜 Code sample

The repository interface is extend by an additional interface. It's implementation is found by the Impl suffix in the same package. Spring Data itself takes care of weaving in the implementation at runtime:

public interface UserRepository extends CrudRepository<User, Long>, CustomUserRepositoryMethods { }


public interface CustomUserRepositoryMethods {
    User calculateAge(User user);
}


public class CustomUserRepositoryMethodsImpl implements CustomUserRepositoryMethods {

    @Override
    public User calculateAge(User user) {
        /* custom code */
    }
}



// Regular method of the repository interface
User user = userRepository.findOne(id);
// Custom method available via the interface, too
userRepository.calculateAge(user);

📘 REST integration

This example shows how to use spring-data-dynamodb with spring-data-rest to automatically expose CRUD operations on DynamoDB entities via REST endpoints.

Further explanation can be found

📜 Code sample

An additional DynamoDB bean must be registered and injected - everything else happens via auto-configuration:

@EnableDynamoDBRepositories(
		mappingContextRef = "dynamoDBMappingContext",
		includeFilters = {@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {
				UserRepository.class}
		)}
)


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

Releases

No releases published

Packages

No packages published

Languages