Posts

Showing posts with the label Spring Data JPA

Product Management System - Spring Boot Thymeleaf PostgreSQL

Image
Here’s a step-by-step guide for building a Spring Boot CRUD application using Thymeleaf as the template engine, PostgreSQL as the database, and Bootstrap for UI styling. This includes a basic explanation of each component. Project Setup To get started, set up your Spring Boot project. Dependencies : Spring Web Spring Data JPA PostgreSQL Driver Thymeleaf Spring Boot DevTools (optional for live reload) Lombok (optional for boilerplate reduction) You can create this setup via Spring Initializr : https://start.spring.io/ Project Structure src / main /java └── com .example .demo ├── controller ├── model ├── repository ├── service └── DemoApplication .java src / main /resources └── templates └── (Thymeleaf templates) └── static └── (CSS, JS, Bootstrap) └── application .properties Steps 1. Configure PostgreSQL In application.properties : spring .datasource .url =jdbc:postgresql: //localhost:5432/your_database_name spring .datasource .username =your_username...

Spring Boot - Testing a JPA application with @DataJpaTest and Testcontainers

Image
In this section, we will learn how to test Repository layer components with @DataJpaTest and Testcontainers in JPA Spring Boot application that uses PostgreSQL as database . 1.  What we will build? We will create a basic JPA Spring Boot application that uses PostgreSQL as database. We will create Repository layer for this application. Finally we will do a testing with help of Testcontainers to verify our system is working as expected. 2. Testcontainers Testcontainers is an open source testing library that allows us to run docker containers directly in our spring boot application in order to facilitate integration tests with real dependencies.  It can provide instances of common databases(here PostgreSQL),  message brokers, Selenium web browsers, or anything else that can run in a Docker container. 3.  @ DataJpaTest Instead of bootstrapping the entire application context for every test,  @DataJpaTest  allows us to initialize only the parts of the Applic...