Skip to main content

Command Palette

Search for a command to run...

Spring & Spring Boot — The Most Beginner Friendly Guide (With Simple Examples)

Published
Spring & Spring Boot — The Most Beginner Friendly Guide (With Simple Examples)
S

I'm Suraj Parmeshwar Shinde, a passionate software developer from Tadshivani, Maharashtra, currently based in Pune. I’ve recently completed my Bachelor of Computer Applications (BCA) from Badrinarayan Barwale College, Jalna. During my graduation, I worked as a Software Intern at PRYM Aerospace Pvt. Ltd., where I contributed to the development of an AI-based crop advisory platform using technologies like Node.js, Flask, and React.js. This experience helped me gain hands-on knowledge of real-world software development and agile practices. For my final year project, I built Medicheck, a full-stack doctor appointment booking system using the MERN stack and Tailwind CSS. It features patient and admin panels, doctor profiles, secure Razorpay payments, and a mobile-responsive interface. My core technical skills include React.js, Node.js, Express.js, JavaScript, Java, MongoDB, SQL, and tools like Git, Postman, Docker, and Netlify. I’m a quick learner who enjoys building real-world applications, solving logical problems, and writing clean, maintainable code. Outside of tech, I enjoy driving and reading books. I’m always eager to grow, collaborate, and contribute to impactful technology solutions.

If you’r starting your Java backend journey, one thing you will hear everywhere is:

👉 “Learn Spring and Spring Boot if you want to get hired.”

But why is Spring so popular? What is the difference between Spring and Spring Boot? How do they work? And how can you build your first backend API with them?

Let’s break it down in the simplest way possible.
This blog is written for complete beginners, with clear examples, simple explanations, and real-world understanding.



🧩 1. What is Spring?

Spring is a powerful, open-source Java framework used to build enterprise applications.

Imagine building a house:

  • Without Spring → you lay bricks manually

  • With Spring → you have tools, machines, and helpers

Spring provides tools & features so that Java developers can build applications faster and cleaner.


⭐ Key Features of Spring

1. Inversion of Control (IoC)

Spring manages object creation for you.

Instead of:

Car car = new Car();

Spring does:

@Autowired
Car car;

Spring framework creates the object internally and injects it wherever needed.


2. Dependency Injection (DI)

This is part of IoC.

You don’t create objects manually → Spring injects them.


3. Spring Modules

Spring is not one framework — it's a collection of modules like:

  • Spring Core

  • Spring MVC

  • Spring JDBC

  • Spring Security

  • Spring AOP

  • Spring ORM

You choose only what you need.



🚀 2. The Problem With Spring

Spring was powerful, but…

❌ Required a lot of XML configuration
❌ Needed many setup steps
❌ Hard for beginners
❌ Projects took long to configure

Developers wanted something simple and fast.


🌟 3. Enter: Spring Boot

Think of Spring Boot as:

👉 Spring on steroids — faster, simpler, smarter

Spring Boot makes Spring EASY.

☕ Spring vs Spring Boot (Simple Table)

FeatureSpringSpring Boot
ConfigurationManual, XMLAuto-configured
Setup TimeSlowVery fast
Embedded Server❌ No✔ Tomcat embedded
Opinionated Defaults❌ No✔ Yes
Use CaseEnterprise-level controlFast development

  • No XML configuration

  • Auto-configured dependencies

  • Embedded server (Tomcat)

  • Production-ready features

  • Actuator (health monitoring)

  • Standalone application using main()


🧱 4. How Spring Boot Works (Simple Explanation)

Spring Boot uses:

✔ Spring Boot Starter Dependencies

spring-boot-starter-web
spring-boot-starter-jpa
spring-boot-starter-test

Each starter contains everything required to start that module.


✔ Auto-Configuration

Spring Boot automatically configures:

  • Database

  • Web server

  • MVC

  • JSON converter

  • Logging

You don’t configure manually.


✔ Opinionated Defaults

Spring Boot gives sensible defaults.


🛠 5. Create Your First Spring Boot Project

We will use Spring Initializr.

🔗 https://start.spring.io/

Choose:

  • Project: Maven

  • Language: Java

  • Spring Boot: Latest

  • Dependencies:

    • Spring Web

    • Spring Boot DevTools

Click Generate Project → import into IntelliJ / Eclipse / VS Code.


📁 6. Project Structure (Explained Simply)

src
 └── main
      ├── java
      │     └── com.example.demo
      │            ├── DemoApplication.java
      │            └── controller
      └── resources
             ├── application.properties
             └── static / templates

DemoApplication.java

Main class where app starts.

@SpringBootApplication
public class DemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}

🌐 7. Create Your First REST API

Step 1: Create Controller

@RestController
public class HelloController {

    @GetMapping("/hello")
    public String sayHello() {
        return "Welcome to Spring Boot!";
    }
}

Step 2: Run Application

Hit:
👉 http://localhost:8080/hello

Output:

Welcome to Spring Boot!


📮 8. POST API Example (Important for Interviews)

@RestController
@RequestMapping("/api/users")
public class UserController {

    @PostMapping("/create")
    public String createUser(@RequestBody User user) {
        return "User created: " + user.getName();
    }
}

User Model:

public class User {
    private String name;
    private String email;

    // getters & setters
}

Send JSON from Postman:

{
  "name": "Suraj",
  "email": "suraj@example.com"
}

Output:

User created: Suraj

🗃 9. Connect Spring Boot With Database (Very Simple)

Add dependency:

spring-boot-starter-data-jpa
mysql-connector-j

application.properties

spring.datasource.url=jdbc:mysql://localhost:3306/testdb
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.hibernate.ddl-auto=update

Create Entity

@Entity
public class Student {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private String name;
}

Create Repository

public interface StudentRepo extends JpaRepository<Student, Long> {
}

Create Service/Controller

@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private StudentRepo repo;

    @PostMapping("/add")
    public Student add(@RequestBody Student student) {
        return repo.save(student);
    }
}

🧰 10. Spring Boot Important Annotations Explained

AnnotationMeaning
@SpringBootApplicationMain class
@RestControllerReturns JSON
@ControllerReturns HTML
@GetMappingGET APIs
@PostMappingPOST APIs
@AutowiredDependency Injection
@ServiceBusiness logic layer
@RepositoryDatabase access
@EntityDatabase table

🔐 11. Spring Boot Security (Beginner Explanation)

Add dependency:

spring-boot-starter-security

Default behavior:

  • App becomes password protected automatically

  • Username: user

  • Password: printed in console


📊 12. Spring Boot Actuator

Actuator exposes production-ready endpoints.

Example:

/actuator/health
/actuator/info
/actuator/metrics

🧭 13. Spring vs Spring Boot Summary

FeatureSpringSpring Boot
ConfigurationManualAutomatic
Setup SpeedSlowFast
Microservices-FriendlyMediumExcellent
Starter DependenciesNoYes
Embedded ServerNoYes

Spring Boot = Spring + Speed + Simplicity.


Final Thoughts

Spring Boot is the #1 Java framework used in modern backend development and microservices architecture.

If you know:

✔ Controllers
✔ DI
✔ JPA + MySQL
✔ Basic Security
✔ REST APIs

You are already ready for backend developer interviews.