DEV Community

Cover image for πŸš€ Spring Boot Journey – Day 2: Setting Up My Development Environment & Building My First REST API
Ashish prajapati
Ashish prajapati

Posted on

πŸš€ Spring Boot Journey – Day 2: Setting Up My Development Environment & Building My First REST API

Welcome to Day 2 of my Spring Boot learning journey! πŸ‘‹

After understanding the fundamentals of Spring Boot on Day 1, today I moved from theory to practice by setting up my complete development environment and building my very first Spring Boot application.

πŸ› οΈ Development Environment

To begin my Spring Boot development, I set up the following tools:

  • Eclipse IDE – For writing and managing Java code.
  • MySQL – To store application data.
  • Spring Boot – The backend framework.
  • Maven – For dependency management and project building.

With everything installed and configured, I was finally ready to write some code.


πŸ“¦ Creating My First Entity: Product

The first class I created was a simple Product class.

It contains three fields:

  • id
  • name
  • price

Along with that, I manually wrote:

  • Constructors
  • Getters
  • Setters
  • toString() method

At first glance, the code looks quite lengthy because Java requires a lot of boilerplate code for a simple class.

πŸ’‘ Note: In upcoming days, I'll learn Lombok, which automatically generates constructors, getters, setters, and other methods, making the code much cleaner and easier to maintain.


πŸ—‚οΈ Understanding Spring Boot Project Structure

To follow Spring Boot's layered architecture, I created three important layers:

πŸ“Œ Controller Layer

The Controller acts as the entry point for client requests.

I created two REST endpoints:

GET /get-all

  • Retrieves all products.
  • Returns a list of products wrapped inside a ResponseEntity.
  • Sends an HTTP 200 OK status.

POST /save-prod

  • Accepts a Product object using @RequestBody.
  • Saves the product.
  • Returns the saved product with HTTP 201 CREATED.

Using ResponseEntity allows us to send both the response data and the appropriate HTTP status code.


πŸ“Œ Repository Layer

Next, I created a ProductRepository.

Instead of writing SQL queries manually, I simply extended:

JpaRepository<Product, Integer>

This provides several built-in database operations like:

  • save()
  • findAll()
  • findById()
  • delete()
  • update()

without writing any implementation code.

That's one of the biggest advantages of Spring Data JPA.


πŸ“Œ Service Layer

The Service layer contains the application's business logic.

Here, I created methods to:

  • Fetch all products.
  • Save a new product.

The service communicates with the repository, while the controller communicates with the service.

This layered architecture keeps the code organized and easier to maintain.


πŸ”„ Request Flow

The complete flow of my application looks like this:

Client Request

⬇️

Controller

⬇️

Service

⬇️

Repository

⬇️

MySQL Database

⬇️

Response Back to Client

This separation of responsibilities is one of the core principles of Spring Boot development.


πŸ“š Concepts I Learned Today

βœ… Setting up Eclipse for Spring Boot development

βœ… Configuring MySQL

βœ… Creating a Spring Boot project

βœ… Understanding layered architecture

βœ… Creating an Entity class

βœ… Building a Repository using JPA

βœ… Writing a Service layer

βœ… Creating REST APIs using @GetMapping and @PostMapping

βœ… Using @RequestBody

βœ… Returning responses with ResponseEntity


πŸ’­ My Takeaway

Today was my first real step into backend development with Spring Boot.

Although the project is simple, it helped me understand how different layers of a Spring Boot application communicate with each other. I also realized why Spring Boot is so popularβ€”it lets developers focus on application logic instead of writing repetitive code.

There's still a lot to learn, but building something that actually runs and responds to API requests feels incredibly rewarding.

Tomorrow I'll continue exploring more Spring Boot concepts and improve this project step by step.

Thank you for following my journey! πŸš€


#SpringBootJourney Day 2

Learning never stops.

One concept.

One project.

One day at a time. πŸ’š

Top comments (0)