了解spring 4(spring-context)maven依赖

Cha*_*per 9 java spring maven

我刚刚开始学习spring,我想使用4.0.4.RELEASE版本 - 它实际上是maven存储库提供的最新版本,所以我的问题在这里:如果我添加这样的依赖:

        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>4.0.4.RELEASE</version>
Run Code Online (Sandbox Code Playgroud)

-it自动将所有"基本"模块(如context,core,aop,beans,expression)添加到我的项目中,但是例如,如果我添加这样的依赖:

    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>4.0.4.RELEASE</version>
Run Code Online (Sandbox Code Playgroud)

-it只会将spring-core jar文件添加到我的项目中,任何人都可以解释为什么它是这样的吗?因为我正在从教程和教程中学习,这个人添加了这两个依赖项 - > spring-core和spring-context,为什么他这样做了?他应该只添加spring-context依赖,结果会是一样的,任何人都可以解释一下吗?谢谢 :)

geo*_*and 10

您需要了解的是Maven处理传递依赖.

在您的情况下,spring-context取决于spring-core并因此当您spring-context在您的声明时pom.xml,Maven将自动解决spring-core传递依赖(这样您不需要声明依赖项的依赖关系等).

spring-core它没有自己的Spring依赖项.这就是为什么当你在它上面使用它时,没有其他的Spring依赖项被添加到类路径中

您可以使用Maven 依赖项插件轻松检查项目的依赖关系树

另外,你可以在它的Maven中心页面(如果存在:)中看到每个模块的依赖关系.是相关页面spring-context

最后一点,您所关注的教程的作者不需要添加spring-core,这可能只是一个疏忽.spring-core只要依赖项的版本同步,声明是一种不会导致问题的冗余.