A study note based on Spring Boot Documentation. The current version is 2.4.0
Spring boot provides a fast getting-started experience without code generation and XML configuration.
Typically, your project declares dependencies to one or more “Starters”. Spring Boot provides a useful Gradle plugin that can be used to simplify dependency declarations and to create executable jars.
For example, to create a MVC application, first add
spring-boot-starter-parent starter to provide default configurations and dependency management (no need to specify version). Then add the
spring-boot-starter-web starter to add Tomcat and Spring MVC. In application main class, use
@EnableAutoConfiguration automatically configure a web application. In
main method, call
SpringApplication.run() to start the application.
@SpringBootApplication annotation combines
@Configuration. It is often placed on your main class, and it implicitly defines a base “search package” for certain items. For example:
Spring boot support “Maven Central” repository. Each release of Spring Boot provides a curated list of dependencies that it supports. You do not need to provide a version for any of these dependencies in your build configuration. The list is available as a standard Bills of Materials (
spring-boot-dependencies) that can be used with both Maven and Gradle.
2 Gradle Plugin
The Spring Boot Gradle Plugin provides Spring Boot support in Gradle. It allows you to package executable jar or war archives, run Spring Boot applications, and use the dependency management provided by
spring-boot-dependencies. The plugin is published to the Spring milestones repository. Then add the plugin with specified version.
The plugin detects when certain other plugins are applied and reacts accordingly. For Kotlin, it requires
org.jetbrains.kotlin.jvm plugin. It also requires
io.spring.dependency-management (this automatically imports the
spring-boot-dependencies bom) or Gradle’s native bom support for dependency management.