Sitemap

Spring Boot Cheat Sheet — Part 1: The Basics You Actually Need 🚀

6 min readSep 2, 2026

--

If you work with Java backend development, chances are you’ve heard about Spring Boot. But Spring Boot can feel overwhelming when you first start.

There are annotations everywhere:

@SpringBootApplication
@RestController
@Service
@Repository
@Autowired
@RequestMapping
@PostMapping
@GetMapping

And then there are concepts like dependency injection, beans, configuration, profiles, DTOs, and more.

So instead of trying to memorize everything, let’s build a simple mental model.

In this series, we’ll create a Payment API and use it to understand the most important Spring Boot concepts.

This is Part 1: Spring Boot Basics.

🧠 First: What is Spring Boot?

At a high level:

Spring Boot helps us build production-ready Java applications with less configuration. Ready to use configurations.

Without Spring Boot, setting up a Spring application traditionally involved a lot of configuration.

Spring Boot gives us:

  • Auto-configuration
  • Embedded servers
  • Starter dependencies
  • Dependency injection
  • Easy application configuration
  • Production-ready features

For example, instead of manually configuring a web server, we can create a Spring Boot application and run it directly.

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

That’s enough to start our application.

But what exactly is happening here?

1️⃣ @SpringBootApplication

This is one of the most important annotations in Spring Boot.

@SpringBootApplication
public class PaymentApplication {
}

Think of it as a combination of three important annotations:

@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan

@SpringBootConfiguration

Tells Spring that this class can provide configuration.

@EnableAutoConfiguration

Spring Boot looks at the dependencies in your project and automatically configures many things for you.

For example, if you add Spring Web, Spring Boot knows that you’re building a web application and configures the required infrastructure.

@ComponentScan

Spring searches your application packages for Spring-managed components such as:

@Component
@Service
@Repository
@Controller
@RestController

Cheat sheet

@SpringBootApplication
|
+-- Configuration
|
+-- Auto Configuration
|
+-- Component Scanning

2️⃣ What is a Spring Bean?

A Spring Bean is an object managed by the Spring container.

For example:

@Service
public class PaymentService {

public void processPayment() {
// payment logic
}
}

Spring creates and manages the PaymentService object for us.

Instead of doing:

PaymentService service = new PaymentService();

we let Spring manage it.

This is where one of the most important Spring concepts comes in:

Dependency Injection

3️⃣ Dependency Injection

Suppose our controller needs PaymentService.

We could manually create it:

PaymentService service = new PaymentService();

But this creates tight coupling.

Instead, we ask Spring to provide the dependency.

The recommended approach is constructor injection.

@RestController
@RequestMapping("/payments")
public class PaymentController {
    private final PaymentService paymentService;    public PaymentController(PaymentService paymentService) {
this.paymentService = paymentService;
}
}

Spring sees that PaymentController requires PaymentService.

Because PaymentService is a Spring bean:

@Service
public class PaymentService {
}

Spring creates it and injects it into the controller.

The mental model

PaymentController
|
| needs
↓
PaymentService
|
| uses
↓
PaymentRepository

Spring manages these dependencies for us.

4️⃣ @RestController

Now let’s expose our payment API.

@RestController
@RequestMapping("/payments")
public class PaymentController {
}

@RestController tells Spring:

“This class handles HTTP requests and returns data directly in the response.”

For example:

@GetMapping("/{id}")
public Payment getPayment(@PathVariable Long id) {
return paymentService.getPayment(id);
}

A request like:

GET /payments/101

can reach this method.

5️⃣ HTTP Mapping Cheat Sheet

These annotations map HTTP requests to Java methods.

AnnotationHTTP MethodTypical Usage@GetMappingGETRetrieve data@PostMappingPOSTCreate/process@PutMappingPUTReplace/update@PatchMappingPATCHPartial update@DeleteMappingDELETEDelete

For our payment API:

@PostMapping
public Payment createPayment(@RequestBody PaymentRequest request) {
return paymentService.createPayment(request);
}

Now:

POST /payments

can create a payment.

6️⃣ @RequestBody

The client might send:

{
"amount": 1500,
"currency": "INR",
"method": "UPI"
}

We can map this JSON to a Java object.

public class PaymentRequest {
    private BigDecimal amount;
private String currency;
private String method;
// getters and setters
}

Then:

@PostMapping
public Payment createPayment(
@RequestBody PaymentRequest request) {
    return paymentService.createPayment(request);
}

@RequestBody tells Spring:

Convert the HTTP request body into this Java object.

7️⃣ @PathVariable

Suppose we want:

GET /payments/101

The 101 is part of the URL.

Get Dolle Priyanka’s stories in your inbox

Join Medium for free to get updates from this writer.

We can capture it using:

@GetMapping("/{id}")
public Payment getPayment(@PathVariable Long id) {
    return paymentService.getPayment(id);
}

Here:

{id}

comes from the URL and becomes:

Long id

8️⃣ @RequestParam

Sometimes we want parameters like:

GET /payments?status=SUCCESS

We can use:

@GetMapping
public List<Payment> getPayments(
@RequestParam String status) {
    return paymentService.getPayments(status);
}

Now:

?status=SUCCESS

becomes:

String status

Quick comparison

/payments/101
↑
@PathVariable
/payments?status=SUCCESS
↑
@RequestParam
POST /payments
{
"amount": 1500
}
↑
@RequestBody

9️⃣ The Most Common Spring Boot Layered Structure

For our payment application, we might organize the code like this:

payment-service
│
├── controller
│ └── PaymentController
│
├── service
│ └── PaymentService
│
├── repository
│ └── PaymentRepository
│
├── dto
│ ├── PaymentRequest
│ └── PaymentResponse
│
├── entity
│ └── Payment
│
└── PaymentApplication

Each layer has a responsibility.

Controller

Handles HTTP requests.

HTTP → Controller

Service

Contains business logic.

Controller → Service

Repository

Handles persistence/data access.

Service → Repository → Database

So the overall flow becomes:

Client
↓
Controller
↓
Service
↓
Repository
↓
Database

This separation is important because it keeps our code maintainable.

🔟 @Service

Business logic generally belongs in the service layer.

@Service
public class PaymentService {
    public Payment createPayment(PaymentRequest request) {        // validate payment        // check business rules        // process payment        // save payment        return payment;
}
}

The controller shouldn’t contain all this logic.

Instead, it should mainly coordinate the request.

@PostMapping
public Payment createPayment(
@RequestBody PaymentRequest request) {
    return paymentService.createPayment(request);
}

Clean and simple.

1️⃣1️⃣ @Repository

The repository layer deals with data access.

For example:

@Repository
public class PaymentRepository {

// database operations
}

If you’re using Spring Data JPA, you can often simplify this even further:

public interface PaymentRepository
extends JpaRepository<Payment, Long> {
}

Spring Data provides many common database operations for you.

For example:

paymentRepository.findById(id);
paymentRepository.save(payment);paymentRepository.deleteById(id);

1️⃣2️⃣ @Autowired — Do I Still Need It?

You may see code like this:

@Autowired
private PaymentService paymentService;

This is field injection.

It works, but constructor injection is generally preferred.

Instead:

private final PaymentService paymentService;
public PaymentController(PaymentService paymentService) {
this.paymentService = paymentService;
}

Why?

Because constructor injection:

  • Makes dependencies explicit
  • Makes fields immutable
  • Makes testing easier
  • Avoids hidden dependencies

A useful rule:

Prefer constructor injection over field injection.

🧩 Putting Everything Together

Let’s build a tiny payment API.

Controller

@RestController
@RequestMapping("/payments")
public class PaymentController {
    private final PaymentService paymentService;    public PaymentController(PaymentService paymentService) {
this.paymentService = paymentService;
}
@PostMapping
public Payment createPayment(
@RequestBody PaymentRequest request) {
return paymentService.createPayment(request);
}
@GetMapping("/{id}")
public Payment getPayment(@PathVariable Long id) {
return paymentService.getPayment(id);
}
}

Service

@Service
public class PaymentService {
    public Payment createPayment(PaymentRequest request) {        // business logic        return new Payment();
}
public Payment getPayment(Long id) { // fetch payment return new Payment();
}
}

The request flow looks like:

POST /payments
↓
PaymentController
↓
PaymentService
↓
PaymentRepository
↓
Database

That simple flow is the foundation of many Spring Boot backend applications.

📝 Spring Boot Cheat Sheet — Part 1

Save this section for later 👇

@SpringBootApplication
→ Main Spring Boot application
@RestController
→ REST API controller
@RequestMapping
→ Base URL mapping
@GetMapping
→ HTTP GET
@PostMapping
→ HTTP POST
@PutMapping
→ HTTP PUT
@PatchMapping
→ HTTP PATCH
@DeleteMapping
→ HTTP DELETE
@RequestBody
→ HTTP request JSON → Java object
@PathVariable
→ Value from URL path
@RequestParam
→ Value from query parameter
@Service
→ Business logic
@Repository
→ Data access
@Component
→ Generic Spring-managed component
Dependency Injection
→ Spring provides required dependencies
Constructor Injection
→ Preferred way to inject dependencies

🎯 The Bigger Picture

The goal isn’t to memorize 50 Spring annotations.

The important thing is to understand how the pieces work together.

When a payment request arrives:

Client
│
│ POST /payments
↓
Controller
│
│ PaymentRequest
↓
Service
│
│ Business Rules
↓
Repository
│
│ Persistence
↓
Database

Once this mental model becomes clear, Spring Boot becomes much less intimidating.

And this is just the beginning.Because writing an API that works is one thing.

Writing an API that is robust and production-ready is another. 🚀

If you’re learning Spring Boot, save this cheat sheet and follow along with the next part.

What Spring Boot concept took you the longest to understand?

Share it in the comments — it might become the next part of this series. 💬

--

--

Dolle Priyanka
Dolle Priyanka

Written by Dolle Priyanka

🌟 Welcome to my corner of creativity! I’m Priyanka, a passionate writer on a mission to share stories that resonate, inspire change, and uplift society. 📚✍️