Skip to main content

Week 3 Day 1 — Spring Boot Mental Model and @SpringBootApplication Deep Dive

Goal

Today I want to understand what Spring Boot actually does.

Main questions:

  1. What is Spring Boot?
  2. What problem does Spring Boot solve?
  3. What is the difference between Spring Framework and Spring Boot?
  4. What does @SpringBootApplication do?
  5. What annotations are inside @SpringBootApplication?
  6. What is @Configuration?
  7. What is @EnableAutoConfiguration?
  8. What is @ComponentScan?
  9. What happens when SpringApplication.run(...) is called?
  10. What are common exam traps?

1. Quick Review from Week 2

In Week 2, I learned:

  • @Configuration marks a class as a source of bean definitions.
  • @Bean marks a method whose return value becomes a Spring bean.
  • External configuration keeps environment values outside Java code.
  • Profiles control which beans and configuration are active.
  • Singleton is the default bean scope.
  • Bean lifecycle includes creation, dependency injection, initialization, post-processing, and destruction.
  • BeanPostProcessor can wrap beans with proxies.

Memory sentence:

Spring creates beans, configures them, scopes them, initializes them, and can wrap them with proxies.

Now I start Spring Boot.


2. What Is Spring Boot?

Spring Boot is a project built on top of the Spring Framework.

It helps create Spring applications faster and with less manual configuration.

Simple definition:

Spring Boot makes Spring applications easier to configure, start, run, and deploy.

Spring Boot gives me:

starter dependencies
auto-configuration
embedded server
externalized configuration
production-ready features
Actuator
opinionated defaults
easy application startup

3. What Problem Does Spring Boot Solve?

Before Spring Boot, Spring applications often needed a lot of manual configuration.

For a web app, I might need to configure:

DispatcherServlet
Tomcat
Jackson JSON converter
Spring MVC setup
DataSource
TransactionManager
JPA EntityManagerFactory
Security filters
Logging
Properties
Profiles

Spring Boot says:

Based on what is on the classpath and in configuration, I can set up many things automatically.

This saves time and reduces boilerplate.


4. Spring Framework vs Spring Boot

Spring Framework

Spring Framework provides the core features:

IoC container
Dependency Injection
AOP
Spring MVC
transactions
data access support
bean lifecycle
resource handling
validation support

Spring Boot

Spring Boot builds on Spring Framework and adds:

auto-configuration
starter dependencies
embedded web server
easy application startup
external configuration defaults
production-ready Actuator
opinionated setup

Memory sentence:

Spring Framework is the foundation. Spring Boot makes Spring easier to configure and run.


5. React / Next.js Comparison

For your React background:

React alone gives component logic.

Next.js adds:

routing
server rendering
build conventions
project structure
API routes
deployment-friendly defaults

Similar idea:

Spring Framework gives core backend features.

Spring Boot adds:

startup conventions
auto-configuration
embedded server
starter dependencies
production defaults

Memory sentence:

Spring Boot is to Spring what Next.js is to React: a powerful layer that adds conventions and production setup.

This is not technically perfect, but it is a helpful mental model.


6. A Minimal Spring Boot App

@SpringBootApplication
public class KlarsyncApplication {

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

This tiny code starts a full Spring Boot application.

It can:

create ApplicationContext
scan components
apply auto-configuration
load external config
start embedded Tomcat if web app
create beans
inject dependencies
run lifecycle callbacks

7. What Is @SpringBootApplication?

@SpringBootApplication is the main annotation used to mark the entry point of a Spring Boot application.

It combines three important annotations:

@Configuration
@EnableAutoConfiguration
@ComponentScan

Very important exam sentence:

@SpringBootApplication is a convenience annotation that combines @Configuration, @EnableAutoConfiguration, and @ComponentScan.


8. The Three Annotations Inside @SpringBootApplication

@SpringBootApplication

is approximately the same as:

@Configuration
@EnableAutoConfiguration
@ComponentScan
public class KlarsyncApplication {
}

Meaning:

@Configuration -> this class can define beans
@EnableAutoConfiguration -> Spring Boot configures beans automatically
@ComponentScan -> Spring scans my packages for components

9. Part 1 — @Configuration

@Configuration means:

This class can contain Spring bean definitions.

Example:

@Configuration
public class AppConfig {

@Bean
public Clock clock() {
return Clock.systemUTC();
}
}

In the main app class:

@SpringBootApplication
public class KlarsyncApplication {
}

because @SpringBootApplication includes @Configuration, the main class itself is also a configuration class.


10. Can I Put @Bean in the Main Class?

Yes.

Example:

@SpringBootApplication
public class KlarsyncApplication {

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

@Bean
public Clock clock() {
return Clock.systemUTC();
}
}

This works.

But in larger applications, it is cleaner to use separate configuration classes:

@Configuration
public class TimeConfig {

@Bean
public Clock clock() {
return Clock.systemUTC();
}
}

Memory sentence:

The main Spring Boot class is also a configuration class, but keep it clean.


11. Part 2 — @ComponentScan

@ComponentScan tells Spring to scan packages for components.

It finds classes annotated with:

@Component
@Service
@Repository
@Controller
@RestController
@Configuration

Example:

@Service
public class TaskService {
}

Spring discovers it through component scanning and registers it as a bean.


12. Default Component Scanning in Spring Boot

Spring Boot starts component scanning from the package of the class annotated with @SpringBootApplication.

Example:

package de.klarsync;

@SpringBootApplication
public class KlarsyncApplication {
}

Spring scans:

de.klarsync
de.klarsync.task
de.klarsync.user
de.klarsync.client
de.klarsync.config
de.klarsync.security

Best practice:

Put the main Spring Boot class in the root package.


13. Bad Package Structure

Bad:

de.klarsync.app
└── KlarsyncApplication.java

de.klarsync.task
└── TaskService.java

Main class:

package de.klarsync.app;

@SpringBootApplication
public class KlarsyncApplication {
}

Spring scans:

de.klarsync.app

But it does not automatically scan:

de.klarsync.task

So TaskService may not become a bean.


14. Part 3 — @EnableAutoConfiguration

This is the most “Spring Boot” part.

@EnableAutoConfiguration tells Spring Boot:

Automatically configure the application based on classpath, properties, and existing beans.

Example:

If Spring Boot sees:

spring-boot-starter-web

on the classpath, it can auto-configure:

embedded Tomcat
DispatcherServlet
Spring MVC
Jackson JSON conversion
error handling
web-related beans

If Spring Boot sees:

spring-boot-starter-data-jpa

it can auto-configure:

DataSource
EntityManagerFactory
TransactionManager
Spring Data JPA repositories
Hibernate integration

15. What Is Auto-Configuration?

Auto-configuration means:

Spring Boot automatically creates configuration and beans based on what it finds in the application.

It looks at:

classpath dependencies
existing beans
application properties
active profiles
web application type
conditions

Example:

If Jackson is on the classpath, Spring Boot configures JSON support.

If Tomcat is on the classpath, Spring Boot starts an embedded web server.

If no custom ObjectMapper exists, Boot can provide one.


16. Auto-Configuration Is Conditional

Spring Boot does not blindly create everything.

It uses conditions.

Common conditions:

@ConditionalOnClass
@ConditionalOnMissingBean
@ConditionalOnBean
@ConditionalOnProperty
@ConditionalOnWebApplication

Example idea:

@Bean
@ConditionalOnMissingBean
public ObjectMapper objectMapper() {
return new ObjectMapper();
}

Meaning:

Create ObjectMapper only if the user has not already defined one.

Memory sentence:

Auto-configuration is automatic, but conditional.


17. Important Auto-Configuration Trap

Spring Boot auto-configuration backs off when I define my own bean in many cases.

Example:

Spring Boot may auto-configure an ObjectMapper.

But if I define:

@Bean
public ObjectMapper objectMapper() {
return new ObjectMapper().findAndRegisterModules();
}

then auto-configuration may not create its default ObjectMapper.

Why?

Because of conditions like:

@ConditionalOnMissingBean

Memory sentence:

My custom bean can replace Boot’s default when auto-configuration backs off.


18. What Are Starter Dependencies?

Spring Boot starters are dependency bundles.

Example:

implementation("org.springframework.boot:spring-boot-starter-web")

This starter brings dependencies for building web apps, such as:

Spring MVC
embedded Tomcat
Jackson
validation-related support depending on setup
logging

Another example:

implementation("org.springframework.boot:spring-boot-starter-data-jpa")

This brings dependencies for:

Spring Data JPA
Hibernate
JPA support
transaction support

19. Starter vs Auto-Configuration

This distinction is very important.

ConceptMeaning
StarterBrings dependencies
Auto-configurationConfigures beans based on dependencies

Example:

spring-boot-starter-web puts Spring MVC and Tomcat on the classpath.
Auto-configuration sees them and configures a web app.

Memory sentence:

Starters bring libraries. Auto-configuration configures them.


20. Embedded Server

Spring Boot web apps usually run with an embedded server.

Example:

java -jar app.jar

Then the app starts Tomcat internally.

I do not need to deploy a WAR file to an external Tomcat.

Spring Boot can use embedded:

Tomcat
Jetty
Undertow

Tomcat is the common default with the web starter.


21. Traditional Spring MVC vs Spring Boot Web App

Traditional style:

Build WAR
Install external Tomcat
Deploy WAR to Tomcat
Configure servlet container

Spring Boot style:

Build executable JAR
Run java -jar app.jar
Embedded Tomcat starts automatically

Memory sentence:

Spring Boot applications are commonly packaged as executable JARs with embedded servers.


22. What Does SpringApplication.run(...) Do?

Example:

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

Simplified flow:

1. Create SpringApplication
2. Determine application type
3. Load environment and properties
4. Create ApplicationContext
5. Register configuration sources
6. Apply auto-configuration
7. Run component scanning
8. Register BeanDefinitions
9. Create singleton beans
10. Inject dependencies
11. Run lifecycle callbacks
12. Start embedded web server if needed
13. Run CommandLineRunner / ApplicationRunner
14. Application is ready

23. Important Startup Flow

Short version for exam:

SpringApplication.run creates and refreshes the ApplicationContext.
During startup, Spring loads configuration, scans components, applies auto-configuration, creates beans, injects dependencies, and starts the embedded web server if it is a web application.

Memory sentence:

SpringApplication.run starts the Spring Boot application by creating and refreshing the ApplicationContext.


24. What Is Application Type?

Spring Boot can detect the application type.

Common types:

none
servlet web application
reactive web application

If Spring MVC is present:

servlet web app

If Spring WebFlux is present:

reactive web app

If no web stack is present:

non-web app

For normal Spring Boot REST APIs with spring-boot-starter-web, it is a servlet web application.


25. What Happens with spring-boot-starter-web?

If I add:

implementation("org.springframework.boot:spring-boot-starter-web")

Spring Boot sees web dependencies and configures:

Servlet web application
embedded Tomcat
DispatcherServlet
Spring MVC
JSON serialization with Jackson
default error handling
HTTP message converters

Then I can write:

@RestController
@RequestMapping("/api/tasks")
public class TaskController {

@GetMapping
public List<String> tasks() {
return List.of("Task 1", "Task 2");
}
}

and it works with little manual setup.


26. What Happens Without spring-boot-starter-web?

If I do not include web dependencies, then:

@RestController

will not be useful because there may be no web server or MVC infrastructure.

Spring Boot may start as a non-web application.

Example use cases:

batch job
CLI app
worker service
scheduled job
message consumer

Spring Boot is not only for web apps.


27. Spring Boot Is Opinionated

Spring Boot provides opinionated defaults.

Meaning:

Spring Boot chooses sensible defaults so I do not need to configure everything manually.

Examples:

default embedded Tomcat for web apps
default JSON handling with Jackson
default logging setup
default application.yml support
default error page / error response
default Actuator conventions

But I can override these defaults when needed.

Memory sentence:

Spring Boot gives defaults, but I can customize them.


28. Spring Boot Does Not Replace Spring

Important:

Spring Boot is not a replacement for Spring Framework.

Spring Boot uses Spring Framework.

Example:

@Service
public class TaskService {
}

This is Spring Framework component model.

@SpringBootApplication

This is Spring Boot convenience.

@Transactional

This is Spring transaction support.

Spring Boot makes configuration easier, but the core concepts are still Spring.


29. Is Spring Boot Magic?

No.

Spring Boot feels like magic because much happens automatically.

But it is based on:

classpath detection
conditional configuration
bean definitions
external properties
Spring IoC container
auto-configuration classes
starter dependencies

Memory sentence:

Spring Boot is not magic. It is conditional configuration.


30. How to See What Boot Configured

Useful tools:

startup logs
debug=true
Actuator /actuator/conditions
Actuator /actuator/beans
Actuator /actuator/configprops

In application.yml:

debug: true

or command line:

java -jar app.jar --debug

This can show auto-configuration condition reports.


31. Auto-Configuration Report

The auto-configuration report helps answer:

Which auto-configurations matched?
Which did not match?
Why did they match?
Why did they not match?

Example:

DataSourceAutoConfiguration matched because DataSource classes were found.
WebMvcAutoConfiguration matched because this is a servlet web application.
SomeSecurityAutoConfiguration did not match because required class was missing.

This is very useful for debugging.


32. Real Question: Why Did Spring Boot Create This Bean?

Possible reasons:

A starter dependency brought a class onto the classpath.
An auto-configuration class matched.
A property enabled the feature.
No custom bean existed, so @ConditionalOnMissingBean allowed default creation.

Example:

I added spring-boot-starter-web.
Spring Boot found Spring MVC and Tomcat.
Web auto-configuration matched.
Spring Boot created web infrastructure beans.

33. Real Question: Why Did Spring Boot Not Create This Bean?

Possible reasons:

Required class is missing from classpath.
Required property is false or missing.
A required bean is missing.
A user-defined bean already exists.
Application is not a web application.
Active profile does not match.
Auto-configuration was excluded.

This is usually visible in the condition report.


34. Excluding Auto-Configuration

Sometimes I want to disable a specific auto-configuration.

Example:

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
public class MyApplication {
}

This tells Spring Boot:

Do not apply DataSourceAutoConfiguration.

Useful if Spring Boot tries to configure a database but I do not want one.


35. Auto-Configuration Exclude in Properties

You may also see:

spring:
autoconfigure:
exclude:
- org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration

For certification, know the concept:

Auto-configuration can be excluded if needed.


36. Common Real Bug: DataSource Error

Problem:

You add JPA starter:

implementation("org.springframework.boot:spring-boot-starter-data-jpa")

but do not configure a database.

Spring Boot tries to auto-configure DataSource.

Then app fails:

Failed to configure a DataSource

Why?

Because JPA starter puts database-related classes on the classpath.

Spring Boot thinks:

This app probably needs a database.

Fix:

configure datasource
add embedded database for tests
remove JPA starter if not needed
exclude DataSourceAutoConfiguration if truly no database

37. Common Real Bug: Web App Not Starting

Problem:

You write:

@RestController
public class TaskController {
}

but the app does not expose HTTP endpoints.

Possible reason:

spring-boot-starter-web is missing

Without the web starter, Boot may not start embedded Tomcat or configure Spring MVC.

Fix:

implementation("org.springframework.boot:spring-boot-starter-web")

38. Common Real Bug: My Custom Bean Is Ignored

Problem:

You define a custom bean, but Boot still seems to use a different one.

Possible reasons:

wrong bean type
wrong bean name
multiple beans exist
@Primary missing
@Qualifier missing
auto-configured bean still active
custom configuration class not scanned
profile does not match

Debug with:

/actuator/beans
/actuator/conditions
startup logs

39. Real Exam Question: @SpringBootApplication

Question:

What does @SpringBootApplication include?

Answer:

It includes:

@Configuration
@EnableAutoConfiguration
@ComponentScan

40. Real Exam Question: Spring vs Spring Boot

Question:

What is the difference between Spring Framework and Spring Boot?

Answer:

Spring Framework provides the core features such as IoC, dependency injection, AOP, MVC, transactions, and data access support. Spring Boot builds on Spring Framework and adds auto-configuration, starter dependencies, embedded server support, externalized configuration conventions, and production-ready features.


41. Real Exam Question: Auto-Configuration

Question:

What is auto-configuration?

Answer:

Auto-configuration is Spring Boot’s mechanism for automatically configuring beans based on classpath dependencies, existing beans, properties, conditions, and the application type.


42. Real Exam Question: Starters

Question:

What is a Spring Boot starter?

Answer:

A starter is a dependency bundle that brings together commonly used dependencies for a specific feature, such as web, JPA, security, or testing.


43. Real Exam Question: Starter vs Auto-Configuration

Question:

What is the difference between starters and auto-configuration?

Answer:

Starters bring dependencies onto the classpath. Auto-configuration sees those dependencies and configures Spring beans based on conditions.


44. Real Exam Question: Embedded Server

Question:

What does embedded server mean in Spring Boot?

Answer:

An embedded server means the web server, such as Tomcat, runs inside the Spring Boot application. The app can be packaged as an executable JAR and started with java -jar, without deploying to an external server.


45. Real Exam Question: @EnableAutoConfiguration

Question:

What does @EnableAutoConfiguration do?

Answer:

It enables Spring Boot’s auto-configuration mechanism, which attempts to configure the application automatically based on classpath, properties, existing beans, and conditions.


46. Real Exam Question: SpringApplication.run

Question:

What does SpringApplication.run(...) do?

Answer:

It starts the Spring Boot application by creating and refreshing the ApplicationContext, loading configuration, applying auto-configuration, scanning components, creating beans, injecting dependencies, running lifecycle callbacks, and starting the embedded server if it is a web application.


47. Real Exam Question: Auto-Configuration Back Off

Question:

What does it mean that auto-configuration “backs off”?

Answer:

It means Spring Boot does not create its default bean when the user has already defined a suitable bean. This is often controlled by @ConditionalOnMissingBean.


48. Real Exam Question: Excluding Auto-Configuration

Question:

How can I exclude an auto-configuration class?

Answer:

One way is:

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
public class MyApplication {
}

Another way is using the spring.autoconfigure.exclude property.


49. Interview Answer

Question:

What is Spring Boot?

Good answer:

Spring Boot is a project built on top of the Spring Framework that makes it easier to create, configure, run, and deploy Spring applications. It provides starter dependencies, auto-configuration, embedded server support, externalized configuration, and production-ready features like Actuator. It reduces manual configuration while still using the core Spring concepts such as IoC, dependency injection, and beans.


50. Interview Answer

Question:

What does @SpringBootApplication do?

Good answer:

@SpringBootApplication is a convenience annotation that combines @Configuration, @EnableAutoConfiguration, and @ComponentScan. @Configuration allows the class to define beans. @EnableAutoConfiguration enables Spring Boot to automatically configure beans based on the classpath and properties. @ComponentScan tells Spring to scan the current package and subpackages for components like services, repositories, controllers, and configuration classes.


51. Interview Answer

Question:

What is auto-configuration in Spring Boot?

Good answer:

Auto-configuration is Spring Boot’s mechanism for automatically configuring the application based on what it finds. It checks classpath dependencies, existing beans, application properties, active profiles, and conditions. For example, if spring-boot-starter-web is on the classpath, Spring Boot can configure embedded Tomcat, Spring MVC, DispatcherServlet, and JSON message converters. Auto-configuration is conditional and can back off when I define my own bean.


52. Interview Answer

Question:

What is the difference between a starter and auto-configuration?

Good answer:

A starter is a dependency bundle. It brings the necessary libraries onto the classpath for a feature, such as web or JPA. Auto-configuration is the mechanism that looks at those libraries and configures Spring beans automatically. In short, starters bring dependencies, and auto-configuration configures them.


53. Interview Answer

Question:

Why is Spring Boot not “magic”?

Good answer:

Spring Boot may look like magic because many things work without manual configuration, but it is based on clear mechanisms. It uses starter dependencies, classpath detection, conditional auto-configuration, external properties, and the Spring IoC container. Auto-configuration classes create beans only when their conditions match. Tools like debug logs and Actuator condition reports can show why a configuration matched or did not match.


54. Tiny Code Practice

Create this minimal app:

@SpringBootApplication
public class DemoApplication {

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

@Bean
public Clock clock() {
return Clock.systemUTC();
}
}

Create a service:

@Service
public class TimeService {

private final Clock clock;

public TimeService(Clock clock) {
this.clock = clock;
}

public Instant now() {
return Instant.now(clock);
}
}

Questions:

  1. Why is Clock a bean?
  2. Why can TimeService inject Clock?
  3. Which annotation inside @SpringBootApplication allows the @Bean method?
  4. Which annotation inside @SpringBootApplication finds TimeService?

Answers:

  1. Because the clock() method is annotated with @Bean.
  2. Because Spring registers Clock in the ApplicationContext.
  3. @Configuration.
  4. @ComponentScan.

55. Tiny Bug Practice

Problem:

package de.klarsync.app;

@SpringBootApplication
public class KlarsyncApplication {
}
package de.klarsync.task;

@Service
public class TaskService {
}

Question:

Why might TaskService not be found?

Answer:

Spring Boot scans from the package of the class annotated with @SpringBootApplication, which is de.klarsync.app. The package de.klarsync.task is not a subpackage of de.klarsync.app, so it is outside the default scan path.

Best fix:

Move KlarsyncApplication to package de.klarsync.

56. Tiny Bug Practice 2

Problem:

You add:

implementation("org.springframework.boot:spring-boot-starter-data-jpa")

but do not configure a database.

The app fails with a DataSource error.

Question:

Why?

Answer:

The JPA starter brings database and JPA classes onto the classpath. Spring Boot’s data source auto-configuration sees them and tries to configure a DataSource. Because no database configuration is provided, startup fails.

Possible fixes:

configure datasource
add embedded database for tests
remove JPA starter if not needed
exclude DataSourceAutoConfiguration if truly no database is needed

Practice Questions and Answers

Question 1

What is Spring Boot?

Answer:

Spring Boot is a project built on top of the Spring Framework that makes Spring applications easier to configure, run, and deploy.


Question 2

What problem does Spring Boot solve?

Answer:

Spring Boot solves the problem of too much manual configuration. It provides auto-configuration, starter dependencies, embedded servers, externalized configuration, and production-ready defaults.


Question 3

What is the difference between Spring Framework and Spring Boot?

Answer:

Spring Framework provides the core features like IoC, dependency injection, AOP, MVC, transactions, and data access support. Spring Boot builds on Spring Framework and adds auto-configuration, starters, embedded server support, and easier application startup.


Question 4

What does @SpringBootApplication include?

Answer:

@SpringBootApplication includes:

@Configuration
@EnableAutoConfiguration
@ComponentScan

Question 5

What does @Configuration do inside @SpringBootApplication?

Answer:

@Configuration means the main application class can act as a source of bean definitions.


Question 6

What does @ComponentScan do inside @SpringBootApplication?

Answer:

@ComponentScan tells Spring to scan the package of the main class and its subpackages for components such as services, repositories, controllers, and configuration classes.


Question 7

What does @EnableAutoConfiguration do?

Answer:

@EnableAutoConfiguration enables Spring Boot’s auto-configuration mechanism.


Question 8

Where does Spring Boot scan components by default?

Answer:

Spring Boot scans from the package of the class annotated with @SpringBootApplication and its subpackages.


Question 9

Why should the main Spring Boot class be in the root package?

Answer:

The main class should be in the root package so Spring can scan all application subpackages automatically.


Question 10

What is auto-configuration?

Answer:

Auto-configuration is Spring Boot’s mechanism for automatically configuring beans based on classpath dependencies, existing beans, properties, conditions, and application type.


Question 11

What does it mean that auto-configuration is conditional?

Answer:

It means Spring Boot creates beans only when certain conditions match, such as a class being present, a property being enabled, or a bean being missing.


Question 12

What is @ConditionalOnMissingBean used for?

Answer:

@ConditionalOnMissingBean is used to create a bean only if the user has not already defined a suitable bean.


Question 13

What does it mean that auto-configuration backs off?

Answer:

Auto-configuration backs off when it does not create its default bean because the user has already defined a suitable bean.


Question 14

What is a Spring Boot starter?

Answer:

A Spring Boot starter is a dependency bundle that brings together common dependencies for a feature such as web, JPA, security, or testing.


Question 15

What is the difference between a starter and auto-configuration?

Answer:

A starter brings dependencies onto the classpath. Auto-configuration configures beans based on those dependencies and other conditions.


Question 16

What does embedded Tomcat mean?

Answer:

Embedded Tomcat means Tomcat runs inside the Spring Boot application. I can run the app as an executable JAR using java -jar.


Question 17

What does SpringApplication.run(...) do?

Answer:

SpringApplication.run(...) starts the Spring Boot application by creating and refreshing the ApplicationContext, loading configuration, applying auto-configuration, scanning components, creating beans, injecting dependencies, running lifecycle callbacks, and starting the embedded server if needed.


Question 18

What happens when I add spring-boot-starter-web?

Answer:

Spring Boot detects web dependencies and configures a servlet web application, embedded Tomcat, DispatcherServlet, Spring MVC, JSON support, and web infrastructure.


Question 19

What happens if I add JPA starter but no database config?

Answer:

Spring Boot may try to auto-configure a DataSource. If no database configuration or embedded database is available, the application may fail to start.


Question 20

How can I debug auto-configuration decisions?

Answer:

I can use startup logs, debug=true, --debug, Actuator /actuator/conditions, /actuator/beans, and /actuator/configprops.

Final Memory Sentences

  • Spring Boot makes Spring easier to configure, run, and deploy.
  • Spring Framework is the foundation. Spring Boot adds convenience and production setup.
  • @SpringBootApplication includes @Configuration, @EnableAutoConfiguration, and @ComponentScan.
  • @Configuration allows bean definitions.
  • @ComponentScan finds my application components.
  • @EnableAutoConfiguration enables Spring Boot auto-configuration.
  • Auto-configuration is automatic but conditional.
  • Starters bring dependencies.
  • Auto-configuration configures beans based on those dependencies.
  • Embedded Tomcat lets the app run as an executable JAR.
  • SpringApplication.run creates and refreshes the ApplicationContext.
  • Spring Boot is not magic; it is conditional configuration.
  • Auto-configuration can back off when I define my own bean.
  • Use debug logs or Actuator conditions to understand auto-configuration.