搭建的工程例子中,指定了spring-boot的spring-boot-starter-parent作为
org.springframework.boot
spring-boot-starter-parent
2.1.18.RELEASE
org.springframework.boot
spring-boot-starter
org.springframework.boot
spring-boot-starter-test
test
每个依赖都有和节点,把节点和节点的信息使用/(正斜线)拼接起来,如果有点分割的地方,点也换成/(正斜线)。
然后在前面加上 https://repo.maven.apache.org/maven2/ 仓库链接,这样就可以找到这个依赖包的版本列表。选一个版本进去,找xxx.pom文件,可从里面看到该依赖包依赖了哪些其它依赖包。
比如:Springboot的包groupId为org.springframework.boot,artifactId为spring-boot-starter,那么先把org.springframework.boot转成/org/springframework/boot,在接上artifactId得/org/springframework/boot/spring-boot-starter,在前面加上仓库域名得:https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter
如果是在IDE里,也可以直接点击对应的包,如果IDE支持的话,也可以直接跳转到依赖的pom文件上。
在 https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/2.7.18/spring-boot-starter-parent-2.7.18.pom 找到一个版本的pom文件,看看spring-boot-starter-parent依赖了哪些包:
org.springframework.boot
spring-boot-dependencies
2.7.18
spring-boot-starter-parent
可以看到,里面也指定了
同样的方式找到spring-boot-dependencies的pom文件:https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-dependencies/2.7.18/spring-boot-dependencies-2.7.18.pom
5.3.31
org.springframework
spring-framework-bom
${spring-framework.version}
pom
import
里面有个
在里面还是没有看到Spring的具体依赖包,但有个spring-framework-bom。再次用同样的办法找到该依赖的pom文件:https://repo.maven.apache.org/maven2/org/springframework/spring-framework-bom/5.3.31/spring-framework-bom-5.3.31.pom
org.springframework
spring-aop
5.3.31
org.springframework
spring-aspects
5.3.31
org.springframework
spring-beans
5.3.31
org.springframework
spring-context
5.3.31
org.springframework
spring-core
5.3.31
org.springframework
spring-expression
5.3.31
org.springframework
spring-jdbc
5.3.31
在这里就能够看到Spring提供的各种各样的依赖。同样,这些依赖还是在
在例子中的pom.xml文件里,指定了两个依赖,其中有一个是测试用的,也就是真正给业务代码用的就一个依赖spring-boot-starter,那它里面用了哪些依赖呢?
找spring-boot-starter的pom文件:https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter/2.7.18/spring-boot-starter-2.7.18.pom
org.springframework.boot
spring-boot
2.7.18
compile
org.springframework.boot
spring-boot-autoconfigure
2.7.18
compile
org.springframework.boot
spring-boot-starter-logging
2.7.18
compile
jakarta.annotation
jakarta.annotation-api
1.3.5
compile
org.springframework
spring-core
5.3.31
compile
org.yaml
snakeyaml
1.30
compile
org.springframework
spring-core
5.3.31
compile
org.springframework
spring-context
5.3.31
compile
里面多依赖一个提供Spring上下文信息的spring-context。
也深入看一下spring-core里面有没有引其它的依赖:
org.springframework
spring-jcl
5.3.31
compile
里面并没有引更多Spring核心的包。
但Spring的依赖注入、面向切面等核心功能包是在哪引入的呢?继续看starter多引的spring-context:https://repo.maven.apache.org/maven2/org/springframework/spring-context/5.3.31/spring-context-5.3.31.pom
org.springframework
spring-aop
5.3.31
compile
org.springframework
spring-beans
5.3.31
compile
org.springframework
spring-core
5.3.31
compile
org.springframework
spring-expression
5.3.31
compile
可以看到Spring的核心包在这里都引到了,也就是说只需要用一个简单的spring-boot-starter依赖,就可以正常使用Spring的主要功能了。
另外,spring-boot-starter及相关的依赖都是明确指定了版本的,这说明spring-boot-starter并不是非得和spring-boot-starter-parent一起使用,其也可以单独使用。
引入spring-boot-starter包,使用Spring的核心功能。