CodeGym /Courses /Module 5. Spring /Introduction to Spring Boot: why you need it and what it ...

Introduction to Spring Boot: why you need it and what it simplifies

Module 5. Spring
Level 1 , Lesson 5
Available

If you compare the Spring Framework to a huge supermarket that has everything you might need, Spring Boot is like a set of ready-made grocery baskets with curated items. There will likely be several typical bundles of things people buy most often. For example: bread, milk, butter, buckwheat, chicken breast, mineral water. Instead of wandering the aisles looking for each item, you just grab the right basket, pay, and use it. Spring Boot is a tool built on top of Spring that took on the job of making app creation easier. It does that by providing autoconfiguration, a set of preconfigured starters, and embedded servers. Simply put, Spring Boot is a handy package that helps you get started right away instead of spending hours on setup.

But why? Why not just use "plain" Spring Framework?

If you haven't manually built a large Spring app yet, here's a quick rundown of what you'd normally have to do:

  1. Manage dependencies by hand (including a pile of XML or lots of annotations).
  2. Wire up an application server like Tomcat separately.
  3. Fine-tune all modules one by one.

Spring Boot simplifies this process with the following key features:

  • Autoconfiguration: no more "where's my XML configuration?". Spring Boot will inspect your project and automatically enable the settings you need.
  • Starters: ready-made dependency bundles with sensible defaults. Need a REST API? Add spring-boot-starter-web and it just works!
  • Embedded web servers: Tomcat, Jetty, or Undertow run out of the box. No more "where did my server go?".
  • Production-ready features: monitoring, metrics, health checks (Actuator) — all built-in.

Basically, Spring Boot is made for lazy developers... I mean, for smart developers who want to focus on business logic instead of endless configuration.


Core components of Spring Boot

Starters Starters are like ingredient kits that let you make a dish without running all over the supermarket. If you need a REST API, just add the starter:


<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
</dependency>

Spring Boot starters already include all the necessary dependencies (for example, Spring Web, Jackson for JSON handling, and so on).

Some popular starters:

  • spring-boot-starter-data-jpa — for working with databases via JPA.
  • spring-boot-starter-security — for adding authentication and authorization.
  • spring-boot-starter-test — for testing applications.

Autoconfiguration Spring Boot inspects which dependencies you've added and automatically applies the right settings. For example, if you use spring-boot-starter-web, Spring Boot will configure the embedded Tomcat, create a DispatcherServlet, and other web components.

Example: if you annotate a class as a REST controller, Spring Boot already knows this is a web app and will set up the server:


@RestController
@RequestMapping("/api")
public class HelloController {

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

Embedded web servers Spring Boot ships with embedded servers like Tomcat. This lets you run the app as a regular Java class instead of deploying a WAR to an external server.

Example:


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

When you run that class, Spring Boot will bring up a server on port 8080 by default.

Production-ready features Spring Boot Actuator gives you metrics and app monitoring. Built-in endpoints provide info about app health, metrics, memory usage, and more.

Example of adding Actuator:


<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

Benefits of Spring Boot

Main upsides

  • Speed of development: you can assemble a first app in literally minutes.
  • Easy configuration: configure via application.properties or application.yml (no XML).
  • DevTools support: hot swapping, automatic restart on code changes.
  • Flexibility: if needed, you can still configure everything manually.

REST API in 5 minutes With Spring Boot, creating a REST API is minimal effort. Example:


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

    @GetMapping("/users")
    public List<String> getUsers() {
        return List.of("Alice", "Bob", "Charlie");
    }
}

Run the app and Spring Boot takes care of the rest. Now you have a REST API that returns a list of users.

Microservices Spring Boot almost feels made for microservices. Fast development, embedded servers, and Spring Cloud support make it a great tool for building scalable, resilient architectures.


Spring Boot makes development easier

Autoconfiguration example Suppose you decide to hook up a database. In plain Spring you'd have to configure the connection manually. In Spring Boot you just put the settings into application.properties:


spring.datasource.url=jdbc:mysql://localhost:3306/mydb
spring.datasource.username=root
spring.datasource.password=secret

Spring Boot will automatically configure the DataSource, the DB connection, and even Hibernate.

Built-in profiles Sometimes you need different settings for development (dev) and production (prod). Spring Boot supports profiles:


# application-dev.properties
server.port=8081

# application-prod.properties
server.port=80

Run the app with the profile you need:


java -jar myapp.jar --spring.profiles.active=prod

When to use Spring Boot?

Spring Boot is great for:

  • REST APIs and CRUD apps.
  • Microservice architectures.
  • Rapid prototyping.
  • Apps where production-ready features matter.

However, if your project is tiny and doesn't need complex dependencies, Spring Boot might be overkill.

Spring Boot is like a coffee machine for developers. Sure, you can brew coffee manually with a filter and a pot, but why bother when you can press one button and get a ready drink? In the next lecture we'll dive into hands-on stuff: we'll create our first Spring app using all the Spring Boot goodies.

Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION