Spring

40 — Spring Boot Intro

Previous: 39 Resilience Patterns · Next: 41 REST & Frontend

▶️ `pkg21spring` · Lab: Project 04 Notes API


What is Spring Boot?

Spring Boot is the opinionated way to build production Java apps — auto-configuration, embedded Tomcat, and a vast ecosystem (Spring Data, Security, Cloud).

Concept What it does
@SpringBootApplication Enables auto-config + component scan
@RestController REST endpoints with @GetMapping, etc.
@Autowired / constructor injection Dependency injection
application.properties Externalized configuration
Spring Data JPA Repository abstraction over Hibernate

File-by-file in `pkg21spring`

File Role
NotesApplication.java Entry point
Note.java JPA @Entity
NoteRepository.java JpaRepository
NoteController.java /api/notes CRUD + CORS
application.properties H2 in-memory DB
bash
1cd pkg21spring2mvn spring-boot:run3curl http://localhost:8080/api/notes

Minimal REST controller

java
1@RestController2@RequestMapping("/api/notes")3public class NoteController {4    private final NoteRepository repo;5 6    public NoteController(NoteRepository repo) { this.repo = repo; }7 8    @GetMapping9    public List<Note> all() { return repo.findAll(); }10}

Learning path for Spring

  1. Solid OOP + JDBC + REST (chapters 10–31)
  2. Run pkg21spring (this chapter)
  3. Read 15 Spring Boot Interview
  4. Add a browser UI in ch.41

Next → 41 REST & Frontend

Full interview topic → 15 Spring Boot

Career guide → 06-career/02-InterviewGuide.md