The most surprising thing about Spring Boot is that it’s less about new Spring features and more about opinionated defaults that make existing Spring features trivial to use.

Imagine you’re building a simple REST API. In traditional Spring, you’d be setting up DispatcherServlet, ViewResolver, @Controller scanning, and a whole mess of XML or Java config. With Spring Boot, you add a few dependencies, and suddenly you have a runnable web server.

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class DemoApplication {

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

    @GetMapping("/hello")
    public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
        return String.format("Hello %s!", name);
    }
}

This single file, with the @SpringBootApplication annotation, bootstraps an embedded Tomcat server, configures a default DispatcherServlet, enables component scanning for @RestController and @Controller classes, and sets up Jackson for JSON serialization. It’s doing a LOT with very little explicit code.

The magic behind this is Spring Boot’s auto-configuration. It looks at your dependencies (e.g., spring-boot-starter-web brings in Tomcat, Spring MVC, Jackson) and intelligently configures beans for you. If you add spring-boot-starter-data-jpa, it will try to configure a DataSource, EntityManagerFactory, and TransactionManager based on properties you provide.

The core problem Spring Boot solves is boilerplate code and configuration complexity. It lets you focus on your application’s business logic rather than plumbing. It achieves this by:

  1. Auto-configuration: As mentioned, it guesses what beans you need based on your classpath.
  2. Starter Dependencies: These are curated sets of dependencies that pull in common libraries for specific use cases (e.g., spring-boot-starter-web for web apps, spring-boot-starter-test for testing). They simplify dependency management.
  3. Embedded Servers: Tomcat, Jetty, or Undertow are bundled directly, so you don’t need to deploy WAR files to an external server. You run a JAR.
  4. Externalized Configuration: Properties can be managed via application.properties or application.yml files, environment variables, command-line arguments, etc., making it easy to deploy the same application in different environments.

The application.properties file is your primary lever for controlling auto-configuration and application behavior. For example, to change the embedded Tomcat port from the default 8080 to 9000, you’d add:

server.port=9000

To configure a database, you might have:

spring.datasource.url=jdbc:postgresql://localhost:5432/mydatabase spring.datasource.username=user spring.datasource.password=password spring.jpa.hibernate.ddl-auto=update

Spring Boot then uses these properties to configure the necessary DataSource and JPA beans.

A common misconception is that Spring Boot hides all configuration. In reality, it hides the common configuration. When you need to deviate from the defaults, you can disable specific auto-configurations and define your own beans using @Configuration and @Bean annotations, or override properties. For example, if you don’t want Spring Boot to auto-configure a DataSource because you’re using a custom connection pool, you can add:

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})

to your main class. This tells Spring Boot to skip the DataSource auto-configuration, allowing you to provide your own DataSource bean definition.

The next concept you’ll encounter is managing different profiles for your application, allowing you to load specific configurations for development, testing, and production environments.

Want structured learning?

Take the full Spring-boot course →