在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
1条答案
按热度按时间yyhrrdl81#
spring-boot-starter
具有以下依赖关系:如果你更换
spring-boot-starter
与spring-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的快速指南