🚀 From Zero to Backend Hero: Building a Blog App with Spring Boot (Part 1)

Hey friends! 👋
Ever wondered how blog apps like Hashnode or Medium work behind the scenes? I decided to build one — from scratch — and take you along for the ride. In this blog series, we’re diving into full-stack development, starting with the backend. And trust me, it’s not as scary as it sounds. 😄

Today, we're setting up the backend engine using Spring Boot, JPA (Hibernate), and MySQL. It’s like assembling the bones and organs before we put on the skin (frontend). Let’s do this! 💪

🧭 What Are We Building Today?

  • A Spring Boot backend project

  • A database connection using MySQL

  • JPA (Hibernate) to handle data like magic

  • Entity classes: User, Post, and Category

  • A clean foundation for our blog app

🛠️ Step 1: Setting Up the Spring Boot Project

I went to start.spring.io — the magical place where all Spring Boot adventures begin.

Here’s what I picked:

Dependencies:

  • Spring Web (to create REST APIs)

  • Spring Data JPA (to talk to the database like a pro)

  • MySQL Driver (because we’re using MySQL)

  • Lombok (to avoid writing boring getter/setter code)

:

🧾 Project Metadata:

yamlCopyEditGroup    : com.pratham.blogapp
Artifact : blogapp
Java     : 21

Click Generate, unzip it, and open in your favorite IDE (I use IntelliJ 🔥). Boom! You’ve got a live Spring Boot app breathing on your machine.

🔗 Step 2: Connecting to MySQL (our database BFF)

Next up — let’s teach our app where to store all those users and posts. For that, we add this config to application.properties:

propertiesCopyEditspring.datasource.url=jdbc:mysql://localhost:3306/blogdb
spring.datasource.username=root
spring.datasource.password=yourpassword

spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect

📝 Replace yourpassword with your real MySQL password (unless you're feeling rebellious 😅).

🧬 Step 3: Creating the Core Entities

These are the characters in our blog story. Let’s start with the User:

javaCopyEdit@Entity
public class User {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    private String name;
    private String email;
    private String password;

    // Add Lombok for cleaner code (e.g., @Data)
}

You can imagine similar classes for Post and Category. They’re like building blocks for our app’s data universe.

📂 Step 4: Repository Layer (where the magic happens)

Instead of writing complex SQL queries, Spring Data JPA gives us shortcuts. Check this out:

javaCopyEditpublic interface UserRepo extends JpaRepository<User, Integer> {}

public interface PostRepo extends JpaRepository<Post, Integer> {}

public interface CategoryRepo extends JpaRepository<Category, Integer> {}

Yup, that’s it. You now have full CRUD access to your database. Insane, right?

🧑‍🔧 What We’ve Built So Far:

✅ A fully bootstrapped Spring Boot app
✅ Connected to MySQL like a pro
✅ Defined our first entities
✅ Set up repositories for easy DB operations

You’re already way ahead of most tutorials. 🔥

⏭️ What’s Coming Next?

In Part 2, we’ll create our REST APIs and connect all the dots. Think user creation, post management, categories, and more. The real action starts there. 🔧💥

If you enjoyed this post, don’t forget to:

💙 Drop a like
📌 Bookmark it
📣 Share with your dev buddies
📬 Follow me for more dev stories and tutorials

🖋️ Written by Prathamesh Ghorapade — just a dev trying to turn coffee into code ☕💻

0
Subscribe to my newsletter

Read articles from Prathamesh Ghorapade directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Prathamesh Ghorapade
Prathamesh Ghorapade