首先,您需要运行 DynamoDB 的本地实例:https://aws.amazon.com/blogs/aws/dynamodb-local-for-desktop-development/
将以下 Repo 添加到您的 build.gradle
repositories {
mavenCentral()
maven { url "http://repo.opensourceagility.com/release/" }
}
添加这些依赖项
dependencies {
compile group: 'org.springframework.data', name: 'spring-data-jpa', version: '1.10.2.RELEASE'
compile group: 'com.amazonaws', name: 'aws-java-sdk-dynamodb', version: '1.11.34'
compile group: 'org.socialsignin', name: 'spring-data-dynamodb', version: '4.2.1'
}
添加这些属性:
amazon.dynamodb.endpoint=http://localhost:8000/
amazon.aws.accesskey=key
amazon.aws.secretkey=key2
创建数据模型:
@DynamoDBTable(tableName = "Table")
public class Table {
private String id;
public Table() {}
@DynamoDBHashKey
@DynamoDBAutoGeneratedKey
public String getId()
{
return id;
}
}
创建一个 CRUD 存储库:
@EnableScan
public interface TableRepository extends CrudRepository<Table,String> {
List<Table> findById(String id);
}