Reputation: 2271
What is the purpose of this POM in Sprint Boot org.springframework.boot.spring-boot
It includes
org.springframework.spring-core
org.springframework.spring-context
So in something like org.springframework.boot.spring-boot-starter-web you have
org.springframework.spring-webmvc
org.springframework.boot.spring-boot-starter
org.springframework.boot.spring-boot-starter-json
org.springframework.boot.spring-boot-starter-tomcat
Why not just make org.springframework.boot.spring-boot-starter-web
org.springframework.spring-webmvc
org.springframework.spring-core
org.springframework.spring-context
org.springframework.boot.spring-boot-starter-json
org.springframework.boot.spring-boot-starter-tomcat
Upvotes: 2
Views: 1502
Reputation: 1275
spring-boot-starter
has following dependencies:
jakarta.annotation-api
spring-core
spring-boot
spring-boot-autoconfigure
spring-boot-starter-logging
if you replace spring-boot-starter
with spring-core
and spring-context
, then you miss out all the classes and annotations that are defined in spring-boot
and spring-boot-autoconfigure
(spring-boot
depends on spring-core
and spring-context
, but it has implemented some important classes itself, see below).
take spring-boot-starter-web
as an example, usually we need to set server.port
in our application.yml
, this property is defined in ServerProperties class in spring-boot-autoconfigure
project(that's why we need spring-boot-starter
in org.springframework.boot.spring-boot-starter-web), there are other commonly used properties such as server.address
, server.servlet.context-path
, and server.ssl.*
....etc.They are all defined here in spring-boot-autoconfigure
project.
in order to auto configure the properties defined in ServerProperties, class ServletWebServerFactoryAutoConfiguration is created to take ServerProperties as a parameter and apply it's values to set up software like tomcat
now see that ServerProperties is neither annotated with @Configuration
nor @Component
, so it wouldn't be instantiated when component-scan is happening, so this annotation EnableConfigurationProperties is created to make sure ServerProperties's instance will be injected. this annotation is defined in spring boot
project, that's why we need spring-boot
dependency. And it's used
here.
for what is a spring boot starter and how it works, here is a helpful article: Quick Guide to Building a Spring Boot Starter
Upvotes: 2