Showing posts with the label Spring Data JDBC

Spring Boot - Testing Spring Data JDBC application with @DataJdbcTest - Example

In this section, we will learn how to test Repository layer components with @DataJdbcTest in Spring Boot application. 1.  @ DataJdbcTest Instead of bootstrapping the entire application context for every test, @DataJdbcTest allows us to initialize the Spring application context with only those beans needed to test Spring Data JDBC-based components. It will auto-configure JdbcTemplate and if an embedded database is available on the classpath, @ DataJdbcTest   will autoconfigure one for testing purposes. By default, tests annotated with @ DataJdbcTest   are transactional and roll back at the end of each test, means we do not need to clean up saved or modified table data after each test. Regular @Component , @Service or @Controller beans are not scanned when using this annotation.  This approach not only speeds up the testing process but also ensures a focused and efficient testing environment. This approach is also known as "slicing" the application context. Find the sample c

Spring Boot + Spring Data JDBC + Microsoft SQL Server - Build REST CRUD APIs

In this section, we will learn how to develop a REST-style web service with  Spring Boot ,  Spring Data JDBC,  and  Microsoft SQL Server . GitHub repository link is provided at the end of this tutorial. You can download the source code.  *Before development, make sure that the Microsoft SQL server is installed on your machine -  SQL Server Downloads | Microsoft Technologies used: Spring Boot 3.0.2 Spring Data JDBC Java 17 Maven  Microsoft SQL Server Driver Microsoft SQL Server These are APIs that Spring Boot backend App will export: 1. Create database. First, you need to create a database in the Microsoft SQL Server.   CREATE DATABASE testdb; 2. Creating a simple spring boot web application: First, open the Spring initializr   Then, Provide the Group and Artifact name. We have provided Group name  and Artifact  spring-boot-spring-data-jdbc-sqlserver-crud . Here I selected the  Maven  project - language  Java 17  -  Spring Boot 3.0.2  and ad