Spring Boot AutoConfigure provides auto-configuration capabilities that automatically configure Spring applications based on jar dependencies present on the classpath
—
Get started with Spring Boot AutoConfigure in minutes.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>4.0.2</version>
</dependency>implementation 'org.springframework.boot:spring-boot-autoconfigure:4.0.2'import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}mvn spring-boot:runor
./gradlew bootRunThe @SpringBootApplication annotation:
@Component, @Service, @Controller classesapplication.properties to configurationimport org.springframework.web.bind.annotation.*;
@RestController
public class HelloController {
@GetMapping("/hello")
public String hello() {
return "Hello, World!";
}
}Visit: http://localhost:8080/hello
Create src/main/resources/application.properties:
server.port=8080
spring.application.name=my-app@SpringBootApplication(exclude = {
DataSourceAutoConfiguration.class
})
public class MyApplication {
// ...
}<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>Auto-configured automatically when H2/MySQL/PostgreSQL is on classpath.
@SpringBootApplication
@EnableCaching
public class MyApplication {
// ...
}<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>Auto-configured with default security settings.
Enable debug mode to see what's being auto-configured:
debug=trueCheck the console output for condition evaluation report.
Application won't start?
Port already in use?
server.port=8081Beans not found?
@Component annotationsSee Troubleshooting Guide for more help.