ChatGPT解决这个技术问题 Extra ChatGPT

spring 3.0 包含哪些 maven 依赖项?

我正在尝试使用 Spring 3.0(和 maven)做我的第一个项目。我在相当多的项目中一直在使用 Spring 2.5(和入门版本)。尽管如此,我还是有点困惑,我必须在 pom.xml 中将哪些模块定义为依赖项。我只想使用核心容器功能(beans、core、context、el)。

我习惯这样做:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring</artifactId>
    <version>2.5.6</version>
</dependency>

但是现在我有点困惑,因为 3.0 版已经没有完整的 spring 模块了。我尝试了以下方法,但没有成功(缺少某些类)。

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>3.0.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-expression</artifactId>
        <version>3.0.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>3.0.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>3.0.0.RELEASE</version>
    </dependency>

任何帮助,将不胜感激!

它实际上按照第二个代码示例中的说明工作。我对其他一些问题感到困惑。对不起,不必要的问题。我还是建议保留这个问题,因为也许人们从 2.5 切换到 3.0 时会遇到同样的问题。

Y
Yasin Okumuş

Keith Donald 在 Spring Blog 上发表了一篇非常好的帖子,详细介绍了操作方法 Obtain Spring 3 Aritfacts with Maven,其中的评论详细说明了您何时需要每个依赖项...

<!-- Shared version number properties -->
<properties>
    <org.springframework.version>3.0.0.RELEASE</org.springframework.version>
</properties>
<!-- Core utilities used by other modules.
    Define this if you use Spring Utility APIs 
    (org.springframework.core.*/org.springframework.util.*)-->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>${org.springframework.version}</version>
</dependency>
<!-- Expression Language (depends on spring-core)
    Define this if you use Spring Expression APIs 
    (org.springframework.expression.*)-->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-expression</artifactId>
    <version>${org.springframework.version}</version>
</dependency>
<!-- Bean Factory and JavaBeans utilities (depends on spring-core)
    Define this if you use Spring Bean APIs 
    (org.springframework.beans.*)-->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-beans</artifactId>
    <version>${org.springframework.version}</version>
</dependency>
<!-- Aspect Oriented Programming (AOP) Framework 
    (depends on spring-core, spring-beans)
    Define this if you use Spring AOP APIs 
    (org.springframework.aop.*)-->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aop</artifactId>
    <version>${org.springframework.version}</version>
</dependency>
<!-- Application Context 
    (depends on spring-core, spring-expression, spring-aop, spring-beans)
    This is the central artifact for Spring's Dependency Injection Container
    and is generally always defined-->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>${org.springframework.version}</version>
</dependency>
<!-- Various Application Context utilities, including EhCache, JavaMail, Quartz, 
    and Freemarker integration
    Define this if you need any of these integrations-->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context-support</artifactId>
    <version>${org.springframework.version}</version>
</dependency>
<!-- Transaction Management Abstraction 
    (depends on spring-core, spring-beans, spring-aop, spring-context)
    Define this if you use Spring Transactions or DAO Exception Hierarchy
    (org.springframework.transaction.*/org.springframework.dao.*)-->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-tx</artifactId>
    <version>${org.springframework.version}</version>
</dependency>
<!-- JDBC Data Access Library 
    (depends on spring-core, spring-beans, spring-context, spring-tx)
    Define this if you use Spring's JdbcTemplate API 
    (org.springframework.jdbc.*)-->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
    <version>${org.springframework.version}</version>
</dependency>
<!-- Object-to-Relation-Mapping (ORM) integration with Hibernate, JPA and iBatis.
    (depends on spring-core, spring-beans, spring-context, spring-tx)
    Define this if you need ORM (org.springframework.orm.*)-->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-orm</artifactId>
    <version>${org.springframework.version}</version>
</dependency>
<!-- Object-to-XML Mapping (OXM) abstraction and integration with JAXB, JiBX, 
    Castor, XStream, and XML Beans.
    (depends on spring-core, spring-beans, spring-context)
    Define this if you need OXM (org.springframework.oxm.*)-->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-oxm</artifactId>
    <version>${org.springframework.version}</version>
</dependency>
<!-- Web application development utilities applicable to both Servlet and 
    Portlet Environments 
    (depends on spring-core, spring-beans, spring-context)
    Define this if you use Spring MVC, or wish to use Struts, JSF, or another
    web framework with Spring (org.springframework.web.*)-->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>${org.springframework.version}</version>
</dependency>
<!-- Spring MVC for Servlet Environments 
    (depends on spring-core, spring-beans, spring-context, spring-web)
    Define this if you use Spring MVC with a Servlet Container such as 
    Apache Tomcat (org.springframework.web.servlet.*)-->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>${org.springframework.version}</version>
</dependency>
<!-- Spring MVC for Portlet Environments 
    (depends on spring-core, spring-beans, spring-context, spring-web)
    Define this if you use Spring MVC with a Portlet Container 
    (org.springframework.web.portlet.*)-->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc-portlet</artifactId>
    <version>${org.springframework.version}</version>
</dependency>
<!-- Support for testing Spring applications with tools such as JUnit and TestNG
    This artifact is generally always defined with a 'test' scope for the 
    integration testing framework and unit testing stubs-->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-test</artifactId>
    <version>${org.springframework.version}</version>
    <scope>test</scope>
</dependency>

谢谢,实际上不得不再次寻找它,因为几天前我发现并丢失了链接。在这里拥有它意味着人们可能比 Spring 博客更容易找到它。
F
FrVaBe

Spring(现在)通过仅使用一个依赖项就可以轻松地将 Spring 添加到项目中,例如

<dependency>
 <groupId>org.springframework</groupId>
 <artifactId>spring-context</artifactId>
 <version>3.1.2.RELEASE</version>
</dependency> 

这将解决

[INFO] The following files have been resolved:
[INFO]    aopalliance:aopalliance:jar:1.0:compile
[INFO]    commons-logging:commons-logging:jar:1.1.1:compile
[INFO]    org.springframework:spring-aop:jar:3.1.2.RELEASE:compile
[INFO]    org.springframework:spring-asm:jar:3.1.2.RELEASE:compile
[INFO]    org.springframework:spring-beans:jar:3.1.2.RELEASE:compile
[INFO]    org.springframework:spring-context:jar:3.1.2.RELEASE:compile
[INFO]    org.springframework:spring-core:jar:3.1.2.RELEASE:compile
[INFO]    org.springframework:spring-expression:jar:3.1.2.RELEASE:compile

查看 Spring Framework documentation 页面了解更多信息。


如果项目中也有 Spring Security,那么这种方法可能会出现问题,因为 Maven 依赖项解析的工作方式(最短路径) - 查看我的Spring Security with Maven文章
@Eugen 好点。在这种情况下,最好只声明 spring-security artifacts 以使用正确的版本解析受支持的“spring-core”工件(不幸的是不是最新的稳定版本)。
I
Igor Kostenko
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>3.0.0.RELEASE</version>
</dependency>

T
Tim

由于这个问题似乎仍然有很多观点,因此请注意对于 Spring 4+,开始使用 Spring BootSpring Boot starter POMs 是最容易的。

使用 Spring Boot,需要管理的依赖项更少(因此冲突也更少),并且设置一个工作良好、集成良好的 Spring Context 要容易得多。我强烈推荐它。


K
Kevin

缺少哪些课程?类名本身应该是缺少模块的一个很好的线索。

仅供参考,我知道包含 uber spring jar 非常方便,但这在与其他项目集成时确实会引起问题。依赖系统背后的好处之一是它可以解决依赖之间的版本冲突。

如果我的库依赖于 spring-core:2.5 而你依赖于我的库和 uber-spring:3.0,那么你的类路径中现在有 2 个版本的 spring。

您可以通过排除来解决此问题,但正确列出依赖项要容易得多,而不必担心它。


R
Ram Sharma

您可以为 spring jar 添加 spring-context 依赖项。您将获得以下罐子。

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>5.0.5.RELEASE</version>
</dependency>

https://i.stack.imgur.com/vjjql.png

如果你还想要 web 组件,你可以使用 spring-webmvc 依赖。

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>5.0.5.RELEASE</version>
</dependency>

https://i.stack.imgur.com/HoGbo.png

你可以使用任何你想要的版本。我在这里使用了 5.0.5.RELEASE。


R
Ritesh Kumar

你可以试试这个

<dependencies>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>3.1.0.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>3.1.0.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>3.1.0.RELEASE</version>
    </dependency>
</dependencies>`

P
Philip Rego

使用 BOM 解决版本问题。

您可能会发现第三方库或另一个 Spring 项目将传递依赖项引入到旧版本。如果您忘记自己显式声明直接依赖项,则可能会出现各种意想不到的问题。为了克服这些问题,Maven 支持“材料清单”(BOM)依赖的概念。

https://docs.spring.io/spring/docs/4.3.18.RELEASE/spring-framework-reference/html/overview.html#overview-maven-bom

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-framework-bom</artifactId>
  <version>3.2.12.RELEASE</version>
  <type>pom</type>
</dependency>