Spring Boot Starter Bağımlılıklar ve Otomatik Konfigürasyon
Spring Boot Auto-Configuration & Starters Explained
Spring Boot auto-configuration and starter dependencies are the two features that make Spring Boot the fastest way to build production-ready Java applications. This guide breaks down how they work under the hood, then walks through a real Reading List app built with Spring MVC, Thymeleaf, JPA, and an embedded H2 database — with zero boilerplate configuration.
Quick summary
- Starters bundle all compatible dependencies in one line
- Auto-configuration detects classpath libraries and wires beans automatically
- Embedded Tomcat starts with no external server setup
- Override any default by declaring your own bean or setting a property
1) The Problem: Manual Configuration Pain
Imagine a supermarket with automatic sliding doors. You walk up and they open. Classic Spring Framework was the opposite — you had to push every door yourself.
Before Spring Boot, a typical project required:
- Adding every dependency individually — and managing version conflicts by hand
- Writing XML or Java
@Configurationclasses for every component - Configuring and deploying to an external application server
- Wiring
DispatcherServlet,DataSource, transaction managers, and view resolvers manually
"Focus on your business logic. I'll handle the infrastructure." — Spring Boot's core promise
2) Spring Boot Starters
A starter is a single dependency that pulls in everything you need for a feature — at mutually compatible versions. No more dependency hell.
spring-boot-starter-web
Spring MVC + embedded Tomcat + Jackson JSON
spring-boot-starter-data-jpa
Hibernate + JPA + transaction management
spring-boot-starter-thymeleaf
Thymeleaf template engine + view resolver
spring-boot-starter-test
JUnit 5 + Mockito + MockMvc + AssertJ
spring-boot-starter-security
Spring Security with sensible defaults
spring-boot-starter-actuator
Production health & metrics endpoints
Note
Version compatibility is managed by the Spring Boot BOM (Bill of Materials). You almost never need to specify a version number for a starter dependency.
3) Auto-Configuration Explained
When Spring Boot starts up, it scans the classpath and runs hundreds of
@Conditional checks. For each library it detects, it creates the right beans
automatically — unless you've already defined your own.
How does @SpringBootApplication enable all of this?
- @EnableAutoConfiguration — triggers classpath scanning & conditional bean creation
- @ComponentScan — registers your own @Service, @Controller, @Repository beans
- @Configuration — marks the class as an additional Spring config source
4) Example App: Reading List
The best way to understand Spring Boot is to build something. This app lets users add and view books in a personal reading list — persisted with JPA and rendered with Thymeleaf.
Tech stack
Bootstrap with Spring Initializr
- Go to start.spring.io and select Gradle – Groovy as the build tool.
- Add dependencies: Web, Thymeleaf, Spring Data JPA, H2 Database.
- Click Generate — Spring Initializr creates the project structure, build file, and
@SpringBootApplicationclass. - Import into your IDE and you're ready to write business logic immediately.
5) Domain Layer — the Book entity
The core domain object is a Book with six fields. Annotate it with JPA annotations:
@Entity
public class Book {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String reader;
private String isbn;
private String title;
private String author;
private String description;
// getters and setters ...
}
What Spring Boot does for you
Because H2 and Hibernate are on the classpath, Spring Boot automatically creates the
BOOK table at startup. No schema.sql or Flyway migration needed for development.
6) Repository Layer — Spring Data JPA
Spring Data JPA eliminates all CRUD boilerplate. Declare an interface extending
JpaRepository and Spring Boot generates the implementation at runtime:
public interface ReadingListRepository
extends JpaRepository<Book, Long> {
List<Book> findByReader(String reader);
}
The findByReader method is derived automatically from its name — no SQL or
@Query annotation required.
7) Web Layer — Controller & Thymeleaf
Controller responsibilities
- GET /{reader} — fetches books from the repository, adds them to the model, returns
readingList.html - POST /{reader} — saves the submitted book entity and redirects back to the reader's page
@Controller
@RequestMapping("/{reader}")
public class ReadingListController {
private final ReadingListRepository repo;
public ReadingListController(ReadingListRepository repo) {
this.repo = repo;
}
@GetMapping
public String readersBooks(@PathVariable String reader, Model model) {
model.addAttribute("books", repo.findByReader(reader));
model.addAttribute("reader", reader);
return "readingList";
}
@PostMapping
public String addToReadingList(@PathVariable String reader, Book book) {
book.setReader(reader);
repo.save(book);
return "redirect:/{reader}";
}
}
Thymeleaf template
Place readingList.html in src/main/resources/templates/.
Spring Boot's auto-configured ViewResolver picks it up with no extra setup:
- Iterates over the books list with
th:each - Shows "No books on the list" when empty using
th:if - Renders an add-book form that posts back to the controller
Tip — static assets
CSS, JavaScript, and images placed in src/main/resources/static/
are served automatically at the root URL — no servlet mapping required.
8) Running the Application
Option 1 — Gradle bootRun
./gradlew bootRun
Option 2 — Build a fat JAR
./gradlew build
java -jar build/libs/readinglist-0.0.1-SNAPSHOT.jar
Either way, Spring Boot starts the following with zero configuration on your part:
- Embedded Tomcat on
http://localhost:8080 - Spring MVC with DispatcherServlet registered
- JPA + Hibernate against an in-memory H2 database
- Thymeleaf view resolver pointed at
/templates/
9) Behind the Scenes: @Conditional magic
Every piece of Spring Boot's auto-configuration is guarded by a @Conditional annotation.
The most important ones are:
How to see which auto-configurations are active
- Add
spring-boot-starter-actuatorto your project - Enable the conditions endpoint:
management.endpoints.web.exposure.include=conditions - Hit
/actuator/conditionsto see every @Conditional evaluation
10) What You Gain with Spring Boot
"You don't push the door. The door opens for you." — and you still control every hinge.
12) Frequently Asked Questions
What is Spring Boot auto-configuration?
Auto-configuration scans the classpath at startup and automatically creates beans based on what libraries are present. For example, if H2 is detected, Spring Boot creates a DataSource bean. You can override any auto-configured bean by declaring your own.
What are Spring Boot starters?
Starters are curated dependency bundles. spring-boot-starter-web
pulls in Spring MVC, embedded Tomcat, and Jackson JSON at compatible versions —
saving you from managing each dependency individually.
Do I need to configure an embedded server manually?
No. Adding spring-boot-starter-web is enough.
Spring Boot starts embedded Tomcat on port 8080 automatically.
You can change the port with server.port=9090 in application.properties.
Can I override Spring Boot auto-configuration?
Yes. Declare your own bean of the same type and Spring Boot's
@ConditionalOnMissingBean will back off automatically.
You can also tune defaults via application.properties without touching Java code.
Is Spring Boot suitable for production?
Absolutely. Spring Boot includes Spring Boot Actuator for health checks, metrics, and monitoring. Fat JARs can be containerized with Docker and deployed to any cloud platform. It's the foundation of the vast majority of enterprise Java microservices.