Spring Boot helps you build Java applications fast. It removes a lot of manual setup. You write less configuration and more business logic.
What is Auto-Configuration?
Auto-configuration means:
Spring Boot automatically configures your app based on what it finds in your project.
It checks:
- Your dependencies (libraries)
- Your settings (application.properties / yaml)
Then it decides what to create and configure.
Example
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
What Gets Auto-Configured?
1. Web Server (Tomcat)
If you add:
spring-boot-starter-web
Spring Boot will:
- Start an embedded Tomcat server
- Set default port (8080)
- Configure basic web setup
- No need to install Tomcat manually.
2. Dispatcher Servlet (Spring MVC)
Spring Boot auto-configures:
- DispatcherServlet
- Request mapping
- JSON handling (via Jackson)
Example controller:
@RestController
public class HelloController {
@GetMapping(„/hello“)
public String hello() {
return „Hello“;
}
}
3. DataSource (Database)
If you add:
spring-boot-starter-data-jpa dependency in your project
And configure:
spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=user
spring.datasource.password=pass
Spring Boot will:
- Create a DataSource
- Configure connection pool
- Setup Hibernate / JPA
– No manual beans required.
4. Entity Manager / JPA
Automatically configured with default values. You can also configure it in application yaml/properties:
- EntityManager
- Transaction management
- Hibernate settings
5. Jackson (JSON)
Spring Boot auto-configures:
- JSON serialization/deserialization
- Converts objects ↔ JSON automatically
6. Logging
Out of the box:
- Logging framework initialized
- Default log format
- No setup needed
7. Configuration Properties
Spring Boot auto-binds properties:
server.port= 9090
– Changes server port without code.
How Does It Decide?
Spring Boot uses:
- @Conditional rules
- Classpath detection
Example:
- If MySQL driver is present → configure DataSource
- If web dependency exists → configure web app
Can You Override?
Yes
You can:
- Add your own configuration
- Override defaults
Example:
@Bean
public DataSource customDataSource() {
// your config
}
Summary
- Spring Boot reduces setup
- Auto-config creates common components
- You focus on business logic
Key idea: “Convention over configuration”

Hinterlasse einen Kommentar