Partner – Jmix-Haulmont – NPI (cat= Spring Boot)
announcement - icon

Whether you're just starting out or have years of experience, Spring Boot is obviously a great choice for building a web application.

Jmix builds on this highly powerful and mature Boot stack, allowing devs to build and deliver full-stack web applications without having to code the frontend. Quite flexibly as well, from simple web GUI CRUD applications to complex enterprise solutions.

Concretely, The Jmix Platform includes a framework built on top of Spring Boot, JPA, and Vaadin, and comes with Jmix Studio, an IntelliJ IDEA plugin equipped with a suite of developer productivity tools.

The platform comes with interconnected out-of-the-box add-ons for report generation, BPM, maps, instant web app generation from a DB, and quite a bit more:

>> Become an efficient full-stack developer with Jmix

Course – RWSB – NPI (cat=REST/Spring Boot)
announcement - icon

Now that the new version of REST With Spring - “REST With Spring Boot” is finally out, the current price will be available until the 22nd of June, after which it will permanently increase by 50$


1. Overview

In this article, we’ll explore the basics of integrating DynamoDB into a Spring Boot Application with a hands-on, practical example project.

We’ll demonstrate how to configure an application to use a local DynamoDB instance using Spring Data. We’ll also create an example data model and repository class and perform actual database operations using an integration test.

2. DynamoDB

DynamoDB is a fully managed hosted NoSQL database on AWS, similar to Cassandra or MongoDB. It offers fast, consistent, and predictable performance and is massively scalable.

You can learn more about DynamoDB on the AWS Documentation.

Let’s install a local instance of DynamoDB to avoid incurring the cost of running a live instance.

For development, running DynamoDB locally makes more sense than running on AWS; the local instance will be run as an executable JAR file.

You can find instructions on how to run DynamoDB locally here.

3. Maven Dependencies

Let’s start by adding the necessary dependencies to start working with DynamoDB using Spring Data:


We must get the latest versions of Spring Data CommonsAWS Java SDK For Amazon DynamoDB, and Spring Data DynamoDB.

4. Configuration

Next, let’s define the following properties in the file:


The access and secret keys listed above are just arbitrary values for your local config. When accessing a local instance of DynamoDB, these fields need to be populated with some values, but they are not needed to authenticate.

The properties will be dynamically pulled out of the file in the Spring config:

  (basePackages = "")
public class DynamoDBConfig {

    private String amazonDynamoDBEndpoint;

    private String amazonAWSAccessKey;

    private String amazonAWSSecretKey;

    public AmazonDynamoDB amazonDynamoDB() {
        AmazonDynamoDB amazonDynamoDB 
          = new AmazonDynamoDBClient(amazonAWSCredentials());
        if (!StringUtils.isEmpty(amazonDynamoDBEndpoint)) {
        return amazonDynamoDB;

    public AWSCredentials amazonAWSCredentials() {
        return new BasicAWSCredentials(
          amazonAWSAccessKey, amazonAWSSecretKey);

5. The Data Model

Let’s now create a POJO model to represent the data stored in DynamoDB.

This POJO will use annotations similar to those used in Hibernate to define the table name, attributes, keys and other aspects of the table.

5.1. Data Model Attributes

The following class, ProductInfo, represents a table with items that contains 3 attributes:

  1. ID
  2. MSRP
  3. Cost

5.2. Java Data Model Class

Let’s create a file called in your data model folder:

@DynamoDBTable(tableName = "ProductInfo")
public class ProductInfo {
    private String id;
    private String msrp;
    private String cost;

    public String getId() {
        return id;

    public String getMsrp() {
        return msrp;

    public String getCost() {
        return cost;

    // standard setters/constructors

6. CRUD Repository

Next, we need to create a ProductRepository interface to define the CRUD functionality we want to build out. Repositories used to read and persist data to and from DynamoDB will implement this interface:

public interface ProductInfoRepository extends 
  CrudRepository<ProductInfo, String> {
    Optional<ProductInfo> findById(String id);

7. Integration Test

Next, let’s create an integration test to ensure we can successfully connect to the local instance of DynamoDB:

@SpringBootTest(classes = Application.class)
@TestPropertySource(properties = { 
  "" })
public class ProductInfoRepositoryIntegrationTest {

    private DynamoDBMapper dynamoDBMapper;

    private AmazonDynamoDB amazonDynamoDB;

    ProductInfoRepository repository;

    private static final String EXPECTED_COST = "20";
    private static final String EXPECTED_PRICE = "50";

    public void setup() throws Exception {
        dynamoDBMapper = new DynamoDBMapper(amazonDynamoDB);
        CreateTableRequest tableRequest = dynamoDBMapper
          new ProvisionedThroughput(1L, 1L));


    public void givenItemWithExpectedCost_whenRunFindAll_thenItemIsFound() { 
        ProductInfo productInfo = new ProductInfo(EXPECTED_COST, EXPECTED_PRICE);; 
        List<ProductInfo> result = (List<ProductInfo>) repository.findAll();

        assertThat(result.size(), is(greaterThan(0)));
        assertThat(result.get(0).getCost(), is(equalTo(EXPECTED_COST))); 

8. Conclusion

And we’re done – we can now connect to DynamoDB from a Spring Boot Application.

Of course, after completing testing locally, we should be able to transparently use a live instance of DynamoDB on AWS and run the deployed code with only minor configuration changes.

As always, the example used in this article is available as a sample project over on GitHub.

Course – RWSB – NPI (cat=REST/Spring Boot)
announcement - icon

Now that the new version of REST With Spring - “REST With Spring Boot” is finally out, the current price will be available until the 22nd of June, after which it will permanently increase by 50$


Course – LSD (cat=Persistence)
announcement - icon

Get started with Spring Data JPA through the reference Learn Spring Data JPA


res – Persistence (eBook) (cat=Persistence)