masrur-ahmed / Pirate_King_Crew_java_Spring_boot

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pirate_King_Crew_java_Spring_boot

This repository uses Java, SpringBoot with DynamoDB You can user swagger to test the REST APIS as well as can run unit/integration test.

Swagger Link: localhost:8082/swagger-ui.html

  • Run mvn verify

  • Test can be run with a local in-memory DynamoDB

  • To use a DynamoDb is necessary to update the aws properties in the file src/main/resources/applications.properties

      server.port=8082
    

and fix as per your requirements in com.example.zorodemo.zorodemo.config.DynamoDbConf.java :

private static final String DYNAMODB_URL = "http://localhost:*YOUR PORT*";
private static final String SIGNINGREGION = *REGION*;
private static final String ACCESSKEY =*ACACCESSKEY*;
private static final String SECRETKEY = *SECRETKEY*;

The code

In this repository to use DynamoDb in Java, it is necessary to add some dependencies, create a DynamoDB Configuration class, and use annotations in the entity classes

Dependencies (pom.xml file)

com.amazonaws::aws-java-sdk-dynamodb
spring-data-dynamodb

Dependencies for Testing with a Local DynamoDB (pom.xml file)

com.amazonaws::DynamoDBLocal

The DynamoDB Configuration class ()

A bean with the name amazonDynamoDB is required, this bean manages the connection with the DynamoDB instance.

	@Bean(name= "dynamoDB")
    public DynamoDBMapper dynamoDBMapper() {
        return new DynamoDBMapper(buildAmazonDynamoDB());
    }

The Pirates entity class (com.example.zorodemo.zorodemo.model.Pirates.java)

The class is annotated to define it as a DynamoDB table

@DynamoDBTable(tableName = "strawhats")
public class Pirates {

Then, a key

@DynamoDBHashKey
@DynamoDBAutoGeneratedKey
private String crewid

And finally, each attribute

@DynamoDBAttribute(attributeName = "firstname")
private String firstname

The Damage entity class (com.example.zorodemo.zorodemo.model.Damage.java)

The class is annotated to define it as a DynamoDB table

@DynamoDBTable(tableName = "damage")
public class Damage {

Then, a key

@DynamoDBHashKey
@DynamoDBAutoGeneratedKey
private String moveid

And finally, each attribute

@DynamoDBAttribute(attributeName = "movename")
private String movename

About


Languages

Language:Java 100.0%