InventoryMS Complete Application – Spring Boot API

In this tutorial, you will learn how to create a complete application step by step using SpringBoot and React frontend.

  1. Introduction to InventoryMS
  2. Create the API Project with Spring Boot
  3. Understanding the Inventory Database Design
  4. Create the Data Models
  5. Create the Repository, Services and Controllers
  6. Enable Spring Security
  7. Implement JPA Auditing
  8. Implement Swagger Documentation
  9. Implement Json Web Token (JWT)

 

Effective way to Learn:

To fully benefit from this course, you need to do the following:

  • Bookmark this page as well as the page for the React UI.
  • Contribute to the main repo. Create a fork of the inventoryms repo. Clone this fork. And contribute changes, report issues, bugs, enhancements etc (How to contribute)
  • Check for daily updates
  • Install necessary applications (IntelliJ, VsCode, MySQL Workbench, Postman Rest Client)
  • Actively participate in the discussions and periodic meetups
  • Reach out to Kindson or the community anytime you are stuck

 

1. Introduction to InventoryMS

This is the first part of our InventoryMS Complete application in React and Spring Boot. You will learn and implement the following concepts:

  • creating an REST API in SpringBoot
  • Implementing Spring Security
  • Implementing JPA Auditing
  • Creating Swagger Documentation
  • Implementing JWT Authentication

Next steps (What you need to do)

  • Step 1 – Fork the inventory-app repo on Github
  • Step 2 – Fork the react-ui-app repo on Github
  • Step 3 – Clone your fork of both repos to a local directory
  • Step 4 – Update the Readme and create your first PR.

If you would like to contribute to the project

  • let me know by mentioning it in the comment with #contribute hashtag
  • provide a brief bio in your first PR on the Readme.md file
  • you’ll be assigned a collaborator/maintainer role on the repo

 

2. Create the API Project with Spring Boot

In this part we would setup the Spring Boot project on IntelliJ and add all the necessary dependencies.

Add the necessary dependencies. The dependencies includes:

  • spring-boot-starter-security
  • mysql-connector-java
  • spring-boot-configuration-processor
  • spring-boot-starter-data-jpa
  • spring-boot-starter-web
  • lombok
  • spring-boot-starter-data-rest

Any other dependency needed would be added as we progress.

Add the MySQL properties in the application.properties file

 

3. Understand the InventoryMS Database Design

Understand the Inventory Data Model

First, we need to obtain the .sql file for the inventory Database from here. You don’t have to execute the statements since the tables would be generated by Hibernate from our Java files

However, take some time to look through the Database Design below and see how various tables relate.

Inventory Management System Database Design
Inventory Management System Database Design

 

4. Create the Data Models

Normally we could generate the Java classes from the database using an IntelliJ plugin called Reverse Engineering (previously JPA Buddy).

However this plugin is available only in the Ultimate Edition of IntelliJ. This tutorial assumes you use IntelliJ Community Edition.

So I will show you a way to generate the Java classes from Database that work both in Community and Ultimate editions of IntelliJ IDE. We would use the help of ChatGPT!

However, you can find all the InventoryMS models here.

You can add some initial data to the database.

 

5. Create the Repository,  Services and Controllers

The Repositories

  • Create the repositories as interfaces that extends JpaRepository. You could create one of these, then copy across and refactor as needed.
  • Annotate the classes with the @Repository annotation.
  • Completed repository files

The Services

  • You will need to create the services each annotated with the @Service annotation
  • Get the complete services here
  • Completed services files

The REST Controllers

  • The REST controllers are annotated with the @RestController annotation
  • Get the complete controllers here
  • Completed controller files

 

6. Enable Spring JPA Auditing

JPA Auditing allows you to automatically add the createdBy, lastUpdatedBy, creationDate, lastUpdatedDate. To enable Jpa Auditing, you can find the steps in the following links:

For JPA Auditing and the next step, Spring Security, you will need to place all the files in the security package.

You can obtain the files for the security package from here.

 

7. Enable Spring Security with Basic Authentication

Basic authentication require username and password to be provided to access protected resources.

 

8. Enable Swagger API Documentation

Swagger allows you to generate OpenAPI specification for your SpringBoot API.

For Spring Boot 3, just add this dependency below, and then visit the link:

<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
    <version>2.0.2</version>
</dependency>

After adding the dependency, you can visit the link:

http://localhost:8080/swagger-ui/index.html

For Spring Boot 2, follow this tutorial to enable Swagger Documentation

 

9. Implement JWT Authentication

Jwt Authentication step by step tutorial

Jwt Authentication video tutorial

User Avatar

kindsonthegenius

Kindson Munonye is currently completing his doctoral program in Software Engineering in Budapest University of Technology and Economics

View all posts by kindsonthegenius →

One thought on “InventoryMS Complete Application – Spring Boot API

Leave a Reply

Your email address will not be published. Required fields are marked *