场景启动器
我们项目只导入了一个web开发的依赖。
1 2 3 4
| <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
|

却导入了许多其他的依赖??这是因为这个就是web场景启动器。
https://docs.spring.io/spring-boot/docs/current/reference/html/using-spring-boot.html#using-boot-starter查看官方文档可以发现。

All official starters follow a similar naming pattern; spring-boot-starter-*
, where *
is a particular type of application.
所有官方的启动器都遵循着一个命名规则就是spring-boot-starter-*
例如

这是为什么会引入这么多依赖呢我们可以查看一下。

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <version>2.4.1</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-json</artifactId> <version>2.4.1</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <version>2.4.1</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>5.3.2</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>5.3.2</version> <scope>compile</scope> </dependency> </dependencies>
|
spring-boot-starter-web
中又导入了其他依赖,其他依赖又导入了依赖。按照依赖传递性原则。所以就有了这么多依赖。
我们可以使用idea查看一下依赖结构图(我删除掉了test依赖)

就能很清晰的看到了上述所说的。可以发现SpringBoot场景启动器最基本的依赖就是spring-boot-starter
SpringBoot官方提供的场景启动器为我们提供了基本上绝大多数够用的依赖。
当然我们也可以自己创建一个场景启动器(后续)。我们要按照官方的第三方场景启动器命名要求。*-spring-boot-starter
