dynamodb-spring-boot
spring boot version
dynamodb-spring-boot-starter version | spring-data-dynamodb version | Spring Boot version |
---|---|---|
0.1.2 | 4.5.x | >= 1.4.0 < 2.0 |
1.0.x | 5.0.x | >= 2.0 |
dynamodb-spring-boot Example
- application.properties
spring.data.dynamodb.access-key=<your access-key>
spring.data.dynamodb.secret-key=<your secret-key>
- PersonRepository
@EnableScan
public interface PersonRepository extends DynamoDBRepository<Person, String> {
}
- Person
@DynamoDBTable(tableName = "persons")
public class Person {
@DynamoDBHashKey
@DynamoDBAutoGeneratedKey
private String id;
private String name;
public Person() {
}
// getter setter etc
}
- Sample
@Bean
CommandLineRunner commandLineRunner(PersonRepository personRepository) {
return args -> {
personRepository.save(Arrays.asList(
new Person("kevin"),
new Person("josh long"))
);
personRepository.findAll()
.forEach(System.out::println);
};
}
Maven Install
<dependency>
<groupId>com.github.wonwoo</groupId>
<artifactId>dynamodb-spring-boot-starter</artifactId>
<version>{version}-RELEASE</version>
</dependency>
Create DDL
spring.data.dynamodb.ddl.enabled=true
spring.data.dynamodb.ddl.enabled
default by false
dynamodb-spring-boot-test Example
@DynamoTest
@DynamoTest
@RunWith(SpringRunner.class)
public class PersonRepositoryTests {
@Autowired
private PersonRepository personRepository;
@Test
public void save() {
List<Person> persons = personRepository.findAll();
assertThat(persons).hasSize(2);
}
}
Maven Install
<dependency>
<groupId>com.github.wonwoo</groupId>
<artifactId>dynamodb-spring-boot-starter-test</artifactId>
<version>{version}-RELEASE</version>
<scope>test</scope>
</dependency>
Embedded Dynamodb setting
- maven dependency
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>DynamoDBLocal</artifactId>
<version>{local.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.almworks.sqlite4java</groupId>
<artifactId>sqlite4java</artifactId>
<version>{local.version}</version>
<scope>test</scope>
</dependency>
- maven plugins
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>process-test-resources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/dependencies</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<argLine>-Dsqlite4java.library.path=${basedir}/target/dependencies</argLine>
</configuration>
</plugin>
</plugins>