VOOZH about

URL: https://www.geeksforgeeks.org/java/how-to-make-a-project-using-spring-boot-mysql-spring-data-jpa-and-maven/

⇱ How to Make a Project Using Spring Boot, MySQL, Spring Data JPA, and Maven? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Make a Project Using Spring Boot, MySQL, Spring Data JPA, and Maven?

Last Updated : 30 Mar, 2026

Spring Boot, along with Spring Data JPA and MySQL, provides a powerful stack for building robust backend applications. Maven is used for dependency management and project build automation, making development faster and more organized.

  • Simplifies backend development using Spring Boot
  • Uses Spring Data JPA for database operations without boilerplate code
  • Integrates MySQL for persistent data storage

Prerequisites

Before starting, ensure you have:

Step-by-Step Implementation

Step 1: Create Maven Project

Create a Maven project and define dependencies in pom.xml.

Project Structure:

👁 Project Structure
 

pom.xml

Step 2: Create Database and Table

Run the following SQL commands:

create database geeksforgeeks; # Creation
use geeksforgeeks #Make the database active

CREATE TABLE `Contest` (

`id` int(11) NOT NULL AUTO_INCREMENT,

`contestName` varchar(45) NOT NULL,

`contestDescription` varchar(45) NOT NULL,

PRIMARY KEY (`id`)

) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;

Step 3: Configure Database Connection

Database connection properties are set in src/main/resources/persistence.xml 

persistence.xml 

Step 4: Configure JPA (EntityManager & Transaction Manager)

Configuration of EntityManagerFactory and TransactionManager

ContestAppConfig.java

Step 5: Create Entity Class

Let's implement the model class.

Contest.java

Step 6: Create Repository Interface

Instead of writing a generic DAO class, a simple interface like below is enough. It extends CrudRepository defined by Spring Data JPA. Common CRUD operations like  save(), findAll(), findById(), delete(), count() etc., are defined by the interface.

ContestRepository.java

Step 7: Create Service Layer

Step 8: Create Test Class

ContestTest.java

Step 9: Run the Application

  • Run ContestTest.java as a Java application
  • Data will be inserted and retrieved from MySQL

Output:

👁 Output
 

As we have tested via contestname as well, in the first output, we saw that one contest got inserted and the same is getting used to test while testing via contestname

👁 Image
 

We can check the DB data also

👁 Database Output

Note: id field is auto-generated. 

Comment