我是否需要显式插入 spring-core 模块?

Do i need to insert spring-core module explicitly?

我实现了一个 spring-webmvc 和 hibernate 项目。但我没有在 pom.xml 文件中包含 spring-core。但是我的代码可以正常工作,依赖注入也可以正常工作。

我的疑惑是

  1. spring-webmvc 和 spring-orm 在没有 spring-core 的情况下如何工作?
  2. 我应该在我的项目中导入 spring-core 以避免将来出现问题吗?

这是我的依赖项 (pom.xml)

<dependencies>
    <!-- Spring MVC Dependency -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <!-- Spring ORM -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <!-- Hibernate Core -->
    <!-- Hibernate Validator -->
    <!-- JSTL Dependency -->
    <!-- Servlet Dependency -->
    <!-- JSP Dependency -->
</dependencies>

spring-webmvc 和 spring-orm 都依赖于 spring 核心,因此您不必显式添加此依赖项。 您可以在此处检查 spring-webmvc 的所有依赖项: https://github.com/spring-projects/spring-framework/blob/master/spring-webmvc/spring-webmvc.gradle

和spring-orm依赖在这里:https://github.com/spring-projects/spring-framework/blob/master/spring-orm/spring-orm.gradle

你也可以使用 mvn dependency:tree 无需查看源代码即可检查所有依赖项的命令

spring-webmvc 以及 spring-orm(以及几乎任何其他 spring-XYZ 模块)都依赖于 spring-core,因此它作为传递依赖项被加载。在此处查看所有依赖项:https://mvnrepository.com/artifact/org.springframework/spring-webmvc/5.1.5.RELEASE