{"id":2006,"date":"2024-09-17T12:00:00","date_gmt":"2024-09-17T10:00:00","guid":{"rendered":"https:\/\/kindsonthegenius.com\/blog\/inventoryms-complete-application-spring-boot-api\/"},"modified":"2026-07-05T03:26:47","modified_gmt":"2026-07-05T01:26:47","slug":"inventoryms-complete-application-spring-boot-api","status":"publish","type":"post","link":"https:\/\/kindsonthegenius.com\/blog\/inventoryms-complete-application-spring-boot-api\/","title":{"rendered":"InventoryMS Complete Application \u2013 Spring Boot API"},"content":{"rendered":"<p>In this tutorial, you will learn how to create a complete application step by step using SpringBoot and React frontend.<\/p>\n<ol>\n<li><a href=\"#t1\">Introduction to InventoryMS<\/a><\/li>\n<li><a href=\"#t2\">Create the API Project with Spring Boot<\/a><\/li>\n<li><a href=\"#t3\">Understanding the Inventory Database Design<\/a><\/li>\n<li><a href=\"#t4\">Create the Data Models<\/a><\/li>\n<li><a href=\"#t5\">Create the Repository, Services and Controllers<\/a><\/li>\n<li><a href=\"#t6\">Enable Spring Security<\/a><\/li>\n<li><a href=\"#t7\">Implement JPA Auditing<\/a><\/li>\n<li><a href=\"#t8\">Implement Swagger Documentation<\/a><\/li>\n<li><a href=\"#t9\">Implement Json Web Token (JWT)<\/a><\/li>\n<li><a href=\"#10\">Implement Roles and Privileges<\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h5><strong>Effective way to Learn:<\/strong><\/h5>\n<p>To fully benefit from this course, you need to do the following:<\/p>\n<ul>\n<li><strong>Bookmark this page<\/strong> as well as the page for the React UI.<\/li>\n<li><strong>Contribute<\/strong> 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)<\/li>\n<li><strong>Check for daily updates<\/strong><\/li>\n<li><strong>Install necessary applications<\/strong> (IntelliJ, VsCode, MySQL Workbench, Postman Rest Client)<\/li>\n<li><strong>Actively participate<\/strong> in the discussions and periodic meetups<\/li>\n<li><strong>Reach out<\/strong> to Kindson or the community anytime you are stuck<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t1\">1. Introduction to InventoryMS<\/strong><\/h4>\n<p>This is the first part of our InventoryMS Complete application in React and Spring Boot. You will learn and implement the following concepts:<\/p>\n<ul>\n<li>creating an REST API in SpringBoot<\/li>\n<li>Implementing Spring Security<\/li>\n<li>Implementing JPA Auditing<\/li>\n<li>Creating Swagger Documentation<\/li>\n<li>Implementing JWT Authentication<\/li>\n<\/ul>\n<p><strong>Next steps (What you need to do)<\/strong><\/p>\n<ul>\n<li><strong>Step 1<\/strong> &#8211; Fork the <em><strong>inventory-app<\/strong><\/em> repo on Github<\/li>\n<li><strong>Step 2<\/strong> &#8211; Fork the <strong><em>react-ui-app<\/em><\/strong> repo on Github<\/li>\n<li><strong>Step 3<\/strong> &#8211; Clone your fork of both repos to a local directory<\/li>\n<li><strong>Step 4<\/strong> &#8211; Update the Readme and create your first PR.<\/li>\n<\/ul>\n<p>If you would like to contribute to the project<\/p>\n<ul>\n<li>let me know by mentioning it in the comment with <em><strong>#contribute<\/strong><\/em> hashtag<\/li>\n<li>provide a brief bio in your first PR on the <em><strong>Readme.md<\/strong><\/em> file<\/li>\n<li>you&#8217;ll be assigned a collaborator\/maintainer role on the repo<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t2\">2. Create the API Project with Spring Boot<\/strong><\/h4>\n<p>In this part we would setup the Spring Boot project on IntelliJ and add all the necessary dependencies.<\/p>\n<p>Add the necessary dependencies. The dependencies includes:<\/p>\n<ul>\n<li>spring-boot-starter-security<\/li>\n<li>mysql-connector-java<\/li>\n<li>spring-boot-configuration-processor<\/li>\n<li>spring-boot-starter-data-jpa<\/li>\n<li>spring-boot-starter-web<\/li>\n<li>lombok<\/li>\n<li>spring-boot-starter-data-rest<\/li>\n<\/ul>\n<p>Any other dependency needed would be added as we progress.<\/p>\n<p>Add the MySQL properties in the <em><strong>application.properties<\/strong><\/em> file<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t3\">3. Understand the InventoryMS Database Design<\/strong><\/h4>\n<p>Understand the Inventory Data Model<\/p>\n<p>First, we need to obtain the .sql file for the inventory Database <a href=\"https:\/\/drive.google.com\/file\/d\/1ZHHvmLEd-E_DAiurk2FssiG9jXyfUa1O\/view?usp=sharing\" target=\"_blank\" rel=\"noopener\">from here<\/a>. You don&#8217;t have to execute the statements since the tables would be generated by Hibernate from our Java files<\/p>\n<p>However, take some time to look through the Database Design below and see how various tables relate.<\/p>\n<figure id=\"attachment_15041\" aria-describedby=\"caption-attachment-15041\" style=\"width: 1831px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/09\/Inventory-Database-Design.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-15041\" src=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/09\/Inventory-Database-Design.png\" alt=\"Inventory Management System Database Design\" width=\"1831\" height=\"1126\" srcset=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/09\/Inventory-Database-Design.png 1831w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/09\/Inventory-Database-Design-300x184.png 300w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/09\/Inventory-Database-Design-1024x630.png 1024w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/09\/Inventory-Database-Design-768x472.png 768w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/09\/Inventory-Database-Design-1536x945.png 1536w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/09\/Inventory-Database-Design-600x369.png 600w\" sizes=\"auto, (max-width: 1831px) 100vw, 1831px\" \/><\/a><figcaption id=\"caption-attachment-15041\" class=\"wp-caption-text\">Inventory Management System Database Design<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t4\">4. Create the Data Models<\/strong><\/h4>\n<p>Normally we could generate the Java classes from the database using an IntelliJ plugin called Reverse Engineering (previously JPA Buddy).<\/p>\n<p>However this plugin is available only in the Ultimate Edition of IntelliJ. This tutorial assumes you use IntelliJ Community Edition.<\/p>\n<p>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!<\/p>\n<p>However, you can find all the <a href=\"https:\/\/drive.google.com\/drive\/folders\/1hjpfaTytND-9mWUnrfc8m_bL5Cjwrl5e?usp=drive_link\" target=\"_blank\" rel=\"noopener\">InventoryMS models here.<\/a><\/p>\n<p>You can add some initial data to the database.<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t5\">5. Create the Repository,\u00a0 Services and Controllers<\/strong><\/h4>\n<p><strong>The Repositories<\/strong><\/p>\n<ul>\n<li>Create the repositories as interfaces that extends <strong><em>JpaRepository<\/em><\/strong>. You could create one of these, then copy across and refactor as needed.<\/li>\n<li>Annotate the classes with the <strong><em>@Repository<\/em><\/strong> annotation.<\/li>\n<li><a href=\"https:\/\/drive.google.com\/drive\/folders\/11oJ6w-TUUsn3jAK5TaKtWqDBWMwvF1h0?usp=drive_link\" target=\"_blank\" rel=\"noopener\">Completed repository files<\/a><\/li>\n<\/ul>\n<p><strong>The Services<\/strong><\/p>\n<ul>\n<li>You will need to create the services each annotated with the <strong><em>@Service<\/em><\/strong> annotation<\/li>\n<li>Get the complete services here<\/li>\n<li><a href=\"https:\/\/drive.google.com\/drive\/folders\/1OwZoy4lFu4x3kNfLQxzd5gO87hK5-Lbn?usp=drive_link\" target=\"_blank\" rel=\"noopener\">Completed services files<\/a><\/li>\n<\/ul>\n<p><strong>The REST Controllers<\/strong><\/p>\n<ul>\n<li>The REST controllers are annotated with the <em><strong>@RestController<\/strong><\/em> annotation<\/li>\n<li>Get the complete controllers here<\/li>\n<li><a href=\"https:\/\/drive.google.com\/drive\/folders\/1LpNjGJjEUM2aBgT_poN8o_oZDE3ttYL2?usp=drive_link\" target=\"_blank\" rel=\"noopener\">Completed controller files<\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t6\">6. Enable Spring JPA Auditing<\/strong><\/h4>\n<p>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:<\/p>\n<ul>\n<li><a href=\"https:\/\/youtu.be\/AZQBzWI3cUg?si=d5QCj4RTRZcBDVkO\" target=\"_blank\" rel=\"noopener\">Jpa Auditing Video Tutorial<\/a><\/li>\n<li><a href=\"https:\/\/www.kindsonthegenius.com\/auditing-in-spring-bootstep-by-step-tutorial\/\">Step by Step tutorial<\/a><\/li>\n<\/ul>\n<p>For JPA Auditing and the next step, Spring Security, you will need to place all the files in the security package.<\/p>\n<p>You can obtain the <a href=\"https:\/\/drive.google.com\/drive\/folders\/1v01gG9G9jHHlNVuVUt-aPnZB6UG_roB8?usp=drive_link\" target=\"_blank\" rel=\"noopener\">files for the security package<\/a> from here.<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t7\">7. Enable Spring Security with Basic Authentication<\/strong><\/h4>\n<p>Basic authentication require username and password to be provided to access protected resources.<\/p>\n<ul>\n<li><a href=\"https:\/\/www.kindsonthegenius.com\/introduction-to-spring-security-a-practical-tutorial\/\" target=\"_blank\" rel=\"noopener\">Follow the steps here to implement Spring Security<\/a><\/li>\n<li><a href=\"https:\/\/youtu.be\/KuzdIOIugJ4?si=pbgrpQdEL6vDPLiP\" target=\"_blank\" rel=\"noopener\">Spring Security video tutorial<\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t8\">8. Enable Swagger API Documentation<\/strong><\/h4>\n<p>Swagger allows you to generate OpenAPI specification for your SpringBoot API.<\/p>\n<p>For Spring Boot 3, just add this dependency below, and then visit the link:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #007700;\">&lt;dependency&gt;<\/span>\r\n    <span style=\"color: #007700;\">&lt;groupId&gt;<\/span>org.springdoc<span style=\"color: #007700;\">&lt;\/groupId&gt;<\/span>\r\n    <span style=\"color: #007700;\">&lt;artifactId&gt;<\/span>springdoc-openapi-starter-webmvc-ui<span style=\"color: #007700;\">&lt;\/artifactId&gt;<\/span>\r\n    <span style=\"color: #007700;\">&lt;version&gt;<\/span>2.0.2<span style=\"color: #007700;\">&lt;\/version&gt;<\/span>\r\n<span style=\"color: #007700;\">&lt;\/dependency&gt;<\/span>\r\n<\/pre>\n<p>After adding the dependency, you can visit the link:<\/p>\n<p><a href=\"#\">http:\/\/localhost:8080\/swagger-ui\/index.html<\/a><\/p>\n<p><a href=\"https:\/\/youtu.be\/s2c_hTqP3yg?si=PUKBV1H3tFOYGyHv\" target=\"_blank\" rel=\"noopener\">For Spring Boot 2, follow this tutorial to enable Swagger Documentation<\/a><\/p>\n<p>Note: remove this dependency if you added it as it would result in http 500 error.<\/p>\n<div>\n<pre>spring-boot-starter-data-rest<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t1\">9. Implement JWT Authentication<\/strong><\/h4>\n<p><a href=\"https:\/\/www.kindsonthegenius.com\/json-web-token-how-to-secure-rest-api-using-jwt-in-spring-boot\/\" target=\"_blank\" rel=\"noopener\">Jwt Authentication step by step tutorial<\/a><\/p>\n<p><a href=\"https:\/\/youtu.be\/IZ2QEPhO7A4?si=8HQnE0eaDwmK4ddP\" target=\"_blank\" rel=\"noopener\">Jwt Authentication video tutorial<\/a><\/p>\n<p>&nbsp;<\/p>\n<h5><strong>SpringBoot Roles and Privileges<\/strong><\/h5>\n<p>I have provided a detail of this in a different tutorial<br \/>\n<a href=\"https:\/\/www.kindsonthegenius.com\/?p=15076&amp;preview=true\" target=\"_blank\" rel=\"noopener\">Roles in Privileges in InventoryMS<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you will learn how to create a complete application step by step using SpringBoot and React frontend. Introduction to InventoryMS Create the &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"pagelayer_contact_templates":[],"_pagelayer_content":"","footnotes":""},"categories":[414],"tags":[],"class_list":["post-2006","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/2006","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/comments?post=2006"}],"version-history":[{"count":1,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/2006\/revisions"}],"predecessor-version":[{"id":2174,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/2006\/revisions\/2174"}],"wp:attachment":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/media?parent=2006"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/categories?post=2006"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/tags?post=2006"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}