Skip to content
PickNTech

Introduction to Spring Boot

What Spring Boot does for you — auto-configuration, beans and dependency injection.

Intermediate18 minUpdated 24 Sept 2026

What you’ll learn

  • What Spring and Spring Boot actually are
  • Creating a project with Spring Initializr
  • Beans, the application context and dependency injection
  • How auto-configuration works

Spring vs Spring Boot

Spring is a framework that manages the objects in your application — creating them, wiring them together and giving them features like transactions and security.

Spring Boot sits on top of Spring and removes the setup. It gives you:

  • Starters — one dependency (e.g. spring-boot-starter-web) pulls in everything for a use case.
  • Auto-configuration — sensible defaults based on what's on your classpath.
  • An embedded server — your app is a single runnable JAR with Tomcat inside.

Create a project

Go to start.spring.io, choose Maven, Java 21+, and add the Spring Web dependency. You'll get this entry point:

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

Run it with ./mvnw spring-boot:run and a web server starts on port 8080.

Beans and dependency injection

Remember programming to interfaces from the OOP lessons? Spring automates the wiring. Mark a class as a component and Spring creates it — a bean — and injects it wherever it's needed:

public interface GreetingService {
    String greet(String name);
}
 
@Service
public class FriendlyGreetingService implements GreetingService {
    public String greet(String name) {
        return "Hello, " + name + "!";
    }
}
 
@RestController
public class GreetingController {
    private final GreetingService service;
 
    // Spring sees the constructor and passes in the GreetingService bean
    public GreetingController(GreetingService service) {
        this.service = service;
    }
 
    @GetMapping("/greet")
    public String greet(@RequestParam String name) {
        return service.greet(name);
    }
}
Component scan→Create beans→Resolve dependencies→Inject via constructor→App ready
What happens at startup inside the application context.

You never call new FriendlyGreetingService(). The application context owns object creation, which makes swapping implementations (and testing) trivial.

Tip

Prefer constructor injection (as above) over @Autowired on fields. Dependencies become explicit, fields can be final, and the class is easy to test without Spring.

Stereotype annotations

AnnotationUse for
@ComponentGeneric bean
@ServiceBusiness logic
@RepositoryData access (adds exception translation)
@RestControllerHTTP endpoints returning data
@Configuration + @BeanBeans you build yourself (e.g. third-party classes)

How auto-configuration works

@SpringBootApplication enables auto-configuration. At startup, Spring Boot checks conditions like "is Jackson on the classpath?" or "has the user defined their own DataSource?" and configures beans only when needed. You override any default by defining your own bean or setting a property:

application.properties
server.port=9090
spring.application.name=employee-api

⚡ Try it yourself

Create a project with Spring Web, add the greeting service and controller above, run it, and open http://localhost:8080/greet?name=YourName. Then add a second implementation of GreetingService and see what error Spring gives you — then fix it with @Primary.

Interview questions

QWhat is dependency injection and why is it useful?+

Dependency injection means an object receives its dependencies from the outside rather than creating them. It decouples classes from concrete implementations, making code easier to test (inject fakes) and to change (swap implementations via configuration).

QWhat does @SpringBootApplication do?+

It combines @Configuration, @EnableAutoConfiguration and @ComponentScan: it marks the class as a source of bean definitions, turns on auto-configuration, and scans its package and sub-packages for components.

Key takeaways

  • Spring Boot = Spring + starters + auto-configuration + embedded server.
  • Beans are objects managed by the application context.
  • Use constructor injection.

Finished this lesson?

Mark it complete to move forward on your roadmap.