org.springframework.boot.spring-boot pom的目的是什么?

p8ekf7hl  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(345)

在sprint boot中使用pom的目的是什么 org.springframework.boot.spring-boot 它包括

org.springframework.spring-core
org.springframework.spring-context

所以在org.springframework.boot.spring-boot-starter-web中

org.springframework.spring-webmvc
org.springframework.boot.spring-boot-starter
org.springframework.boot.spring-boot-starter-json
org.springframework.boot.spring-boot-starter-tomcat

为什么不直接做 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

yyhrrdl8

yyhrrdl81#

spring-boot-starter 具有以下依赖关系:

jakarta.annotation-api
spring-core
spring-boot
spring-boot-autoconfigure
spring-boot-starter-logging

如果你更换 spring-boot-starterspring-core 以及 spring-context ,则会丢失中定义的所有类和注解 spring-boot 以及 spring-boot-autoconfigure ( spring-boot 取决于 spring-core 以及 spring-context ,但它自己实现了一些重要的类(见下文)。
采取 spring-boot-starter-web 举个例子,通常我们需要 server.port 在我们的 application.yml ,此属性在中的serverproperties类中定义 spring-boot-autoconfigure 项目(这就是为什么我们需要 spring-boot-starter 在org.springframework.boot.springbootstarterweb)中,还有其他常用属性,如 server.address , server.servlet.context-path ,和 server.ssl.* ……等等,它们在这里都有定义 spring-boot-autoconfigure 项目。
为了自动配置serverproperties中定义的属性,创建了类servletwebserverfactoryautoconfiguration,将serverproperties作为参数并应用其值来设置像tomcat这样的软件
现在可以看到serverproperties既没有用 @Configuration 也不是 @Component ,因此在进行组件扫描时不会示例化它,因此创建此annotation enableconfigurationproperties以确保将注入serverproperties的示例。此注解在中定义 spring boot 项目,所以我们需要 spring-boot 附属国。在这里用的。
关于什么是springbootstarter及其工作原理,这里有一篇有用的文章:构建springbootstarter的快速指南

相关问题