Spring framework 6.1 introduced a new JdbcClient API, which is a wrapper on top of JdbcTemplate, for performing database operations using a fluent API. Spring Boot 3.2 includes Spring framework 6.1, so let’s take a quick look at how we can use JdbcClient to implement various database operations in a simplified manner. First, let’s go to https://start.spring.io/ and create a Spring Boot application by selecting Spring JDBC, PostgreSQL Driver, Flyway Migration, and Testcontainers starters.
Continue reading »Spring Boot REST API Best Practices - Part 4
In this Spring Boot REST API Best Practices series, we have learned how to implement CRUD operations so far. In this Part-4, we will explore how to implement exception handling for our APIs. 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 Spring Boot REST API Best Practices - Part 4 : Exception Handling in REST APIs (This article) You can find the sample code for this tutorial in this GitHub repository.
Continue reading »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
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
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
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 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
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
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
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 »