Spring Boot REST API Best Practices - Part 3

Spring Boot REST API Best Practices - Part 3

In this Spring Boot REST API Best Practices - Part-3, we will see how to implement FindById and DeleteById API endpoints. Spring Boot REST API Best Practices - Part 1 : Implementing Get Collection API Spring Boot REST API Best Practices - Part 2 : Implementing Create and Update APIs Spring Boot REST API Best Practices - Part 3 : Implementing FindById and DeleteById APIs (This article) Spring Boot REST API Best Practices - Part 4 : Exception Handling in REST APIs You can find the sample code for this tutorial in this GitHub repository.

Continue reading »
Spring Boot REST API Best Practices - Part 2

Spring Boot REST API Best Practices - Part 2

In this Spring Boot REST API Best Practices - Part-2, I will explain some of the best practices we should follow while implementing Create and Update API endpoints. Spring Boot REST API Best Practices - Part 1 : Implementing Get Collection API Spring Boot REST API Best Practices - Part 2 : Implementing Create and Update APIs (This article) Spring Boot REST API Best Practices - Part 3 : Implementing FindById and DeleteById APIs Spring Boot REST API Best Practices - Part 4 : Exception Handling in REST APIs This article is a continuation of Spring Boot REST API Best Practices - Part 1.

Continue reading »
Spring Boot REST API Best Practices - Part 1

Spring Boot REST API Best Practices - Part 1

In this Spring Boot REST API Best Practices Series, I will explain some of the best practices we should follow while implementing REST APIs. Also, I will explain some of the common mistakes developers do and how to avoid them. Spring Boot REST API Best Practices - Part 1 : Implementing Get Collection API (This article) Spring Boot REST API Best Practices - Part 2 : Implementing Create and Update APIs Spring Boot REST API Best Practices - Part 3 : Implementing FindById and DeleteById APIs Spring Boot REST API Best Practices - Part 4 : Exception Handling in REST APIs In this Part-1, we are going to implement our first API endpoint which is to fetch a list of resources.

Continue reading »
Spring Boot Flyway Database Migration Tutorial

Spring Boot Flyway Database Migration Tutorial

In the previous Spring Boot JdbcTemplate Tutorial we have seen how to initialize database using schema.sql and data.sql scripts. This may be useful for demos and quick prototypes, but for real world applications we should use a database migration tool. Flyway is one of the most popular Java-based database migration libraries. Database migrations can be performed using Flyway as a standalone library, using flyway-maven-plugin or using Flyway Gradle plugin. Spring Boot provides out-of-the-box support for Flyway database migrations.

Continue reading »
Spring Boot Database Transaction Management Tutorial

Spring Boot Database Transaction Management Tutorial

Spring provides a high-level abstraction on top of JDBC with JdbcTemplate to make it easier to perform database operations. Spring also provides a high-level abstraction on top of JPA with Spring Data JPA to make it easy to implement CRUD operations, sorting, pagination, etc. Whether you use JdbcTemplate or JPA/Hibernate or Spring Data JPA, you need to take care of handling database transactions. A database transaction is a single unit of work, which either completes fully or does not complete at all, and leaves the database in a consistent state.

Continue reading »
Spring Boot JdbcTemplate Tutorial

Spring Boot JdbcTemplate Tutorial

Introducing Spring Boot JDBC Support Spring’s JdbcTemplate provides high-level abstraction on top of DataSource to perform database operations. In addition to that Spring’s declarative Transaction Management capabilities helps to manage database transactions in a simplified way without having to write boilerplate code. Spring Boot simplifies the configuration of DataSource, TransactionManager, etc. by using it’s AutoConfiguration mechanism. How SpringBoot AutoConfiguration magic works? If you want to learn more about Spring Boot AutoConfiguration, see How SpringBoot AutoConfiguration magic works?

Continue reading »
Spring Boot Profiles Tutorial

Spring Boot Profiles Tutorial

Introducing Spring Profiles Typically, software applications run in different environments. During development, it will be local, and then we may deploy it on QA, Staging, Performance and finally in Production environments. You may have to configure your application with different configuration properties while running the application in different environments. For example, if you are using a database then you may configure the database connection properties to a locally running database during development.

Continue reading »
Spring Boot Logging Tutorial

Spring Boot Logging Tutorial

Logging is a common and important requirement for running applications in production. Spring Boot provides great support for application logging out of the box and offers various customization options. In this tutorial, you will learn how to implement logging in your Spring Boot application using Logback and Log4j2. Getting Started with Spring Boot If you are new to Spring Boot, refer Getting Started with Spring Boot tutorial to learn how to create a Spring Boot project.

Continue reading »
Spring Boot Application Configuration Tutorial

Spring Boot Application Configuration Tutorial

In the previous Spring Boot Testing Tutorial, we have learned how to write unit, slice and integration tests for a Spring Boot application. In this tutorial, you will learn how to configure your Spring Boot application using properties and YAML files for running the application in different environments. Externalizing Spring Boot Application Configuration Any non-trivial application will have some configuration that you would like to make it configurable instead of hard-coding those values in the application code.

Continue reading »
Spring Boot Testing Tutorial

Spring Boot Testing Tutorial

In the previous Getting Started with Spring Boot tutorial, we have learned how to create a Spring Boot application and built a simple REST API. In this tutorial, you will learn how to write unit, slice and integration tests for your Spring Boot application. Testing Spring Boot applications We should write Unit Tests to verify the business logic of a particular unit(a class, a method, or a set of classes), and they shouldn’t be talking to any external services like database, queues or other webservices etc.

Continue reading »