spring 整个 org.springframework 的 Maven 依赖

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6398421/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 04:33:26  来源:igfitidea点击:

Maven dependency for whole org.springframework

springmavendependencies

提问by sergionni

How to set Maven dependency for all org.springframework?

如何为所有人设置 Maven 依赖项org.springframework

I mean, how to do it in couple lines,instead of providing dependency for every module,e.g.:

我的意思是,如何在几行中做到这一点,而不是为每个模块提供依赖,例如:

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

etc..

等等..

thank you for help

谢谢你的帮助

采纳答案by Spanky Quigman

As noted in other answers, you only want to use what you actually need, e.g. if you need the Spring Web framework, then get that. However, you can greatly simplify and reduce the set of dependencies listed in your pom.xml by doing a bit of dependency analysis and only specifying the highest levelof required dependency.

正如其他答案中所指出的,您只想使用您实际需要的东西,例如,如果您需要 Spring Web 框架,那么就获取它。但是,您可以通过进行一些依赖项分析并仅指定所需依赖项的最高级别来极大地简化和减少 pom.xml 中列出的依赖项集。

So for example, suppose you have the following dependencies (note that I'm using the artifact IDs for the Spring EBR repository instead of Maven Central; see this article for more info on the difference):

例如,假设您有以下依赖项(请注意,我使用的是 Spring EBR 存储库的工件 ID,而不是 Maven Central;有关差异的更多信息,请参阅本文):

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>org.springframework.context</artifactId>
    <version>${org.springframework-version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>org.springframework.web.servlet</artifactId>
    <version>${org.springframework-version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>org.springframework.transaction</artifactId>
    <version>${org.springframework-version}</version>
</dependency>

As it happens, though, the Spring Web stuff actually already has a dependency on the context library, so you can just remove the context reference:

但碰巧的是,Spring Web 的东西实际上已经依赖于上下文库,因此您可以删除上下文引用:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>org.springframework.web.servlet</artifactId>
    <version>${org.springframework-version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>org.springframework.transaction</artifactId>
    <version>${org.springframework-version}</version>
</dependency>

This will get you the context library without specifically referencing it, since it's brought in implicitly by the dependency in the Web library.

这将为您提供上下文库,而无需专门引用它,因为它是由 Web 库中的依赖项隐式引入的。

If you have IntelliJ or m2eclipse or something like that in your IDE, you can get these dependencies displayed right in the IDE, either through a dependency hierarchy display or even in a dependency graph, which is basically a UML chart.

如果您的 IDE 中有 IntelliJ 或 m2eclipse 或类似的东西,您可以在 IDE 中直接显示这些依赖项,可以通过依赖项层次结构显示,甚至在依赖关系图中,这基本上是一个 UML 图表。

For stand-alone Maven, I think you just do:

对于独立的 Maven,我认为您只需:

mvn dependencies:list

More on the dependencies plugin is on the plugin site.

有关依赖项插件的更多信息,请访问插件站点。

This approach keeps your dependencies very explicit and your application footprint much smaller, which is basically what everyone else is warning about, but can reduce the number of dependencies you have to list in your pom.xml, which is what I think you're trying to solve.

这种方法使您的依赖项非常明确,并且您的应用程序占用空间要小得多,这基本上是其他人都在警告的,但可以减少您必须在 pom.xml 中列出的依赖项数量,我认为您正在尝试这样做来解决。

回答by subhashis

You can do it like

你可以这样做

<properties>
    <org.springframework.version>3.0.5.RELEASE</org.springframework.version>
</properties>

<dependencies>
    <!-- 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>

回答by Daniel Perník

This answer is aimed to newer version 4.X.X

此答案针对较新版本 4.XX

If you want to handle versions of dependencies more efficiently use this code before your <dependencies></dependencies>tags.

如果您想更有效地处理依赖项的版本,请在<dependencies></dependencies>标记之前使用此代码。

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-framework-bom</artifactId>
            <version>4.2.2.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

Benefit of using the BOMis that you no longer need to specify the version of dependency. So your dependencies should looks like:

使用BOM 的好处是您不再需要指定依赖项的版本。因此,您的依赖项应如下所示:

<dependencies>
    <!-- Spring framework -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
    </dependency>
</dependencies>

回答by abalogh

There is no way, and there should be none. You should only use the jars you really need, no need for allspring jars. For 2.x there used to be a spring.jarbut in every project I've seen that used, it caused version collision problems.

没有办法,也不应该有。你应该只使用你真正需要的罐子,不需要所有的弹簧罐。对于 2.x,曾经有一个,spring.jar但在我见过的每个项目中,它都会导致版本冲突问题。

If you are using any subprojects from Spring, watch it that sometimes they still pull Spring 2.5 (e.g. Spring Batch and I think Spring Web Flow as well), in this case you should use the exclusionstag in your pom.xml.

如果您正在使用 Spring 的任何子项目,请注意有时它们仍然使用 Spring 2.5(例如 Spring Batch,我认为 Spring Web Flow 也是如此),在这种情况下,您应该exclusions在 pom.xml 中使用该标记。

Not the most convenient to assemble it the first time, but then you can reuse it in your other projects.

第一次组装它不是最方便的,但是您可以在其他项目中重复使用它。

回答by Alex Gitelman

Create module with packaging pomand list all Spring dependencies there. Call it something like SpringDependencies.

创建带有打包的模块pom并在那里列出所有 Spring 依赖项。称之为SpringDependencies.

Then in each of your modules, depend on SpringDependenciesmodule. That will transitively pull all Spring dependencies.

然后在你的每个模块中,依赖SpringDependencies模块。这将传递性地拉取所有 Spring 依赖项。

回答by Ji?í Vypěd?ík

There was such an all-in-one module in Spring 2.x, however it didn't survive the module refactoring happened in Spring 3.x. So, the answer is 'No'.

Spring 2.x 中有这样一个一体化模块,但是它没有在 Spring 3.x 中发生的模块重构中幸存下来。所以,答案是“不”。

回答by Laurent Pireyn

There's no wildcards whatsoever in the Maven dependencies, and there's no artifact that gathers all Spring modules anymore. Does your project really use allSpring modules anyway?

Maven 依赖项中没有任何通配符,并且不再有收集所有 Spring 模块的工件。无论如何,您的项目是否真的使用了所有Spring 模块?

回答by Akshay Shet

Spring-context internally resolves other dependencies. Please find below the dependency tree.

Spring-context 在内部解析其他依赖项。请在依赖树下面找到。

[INFO] com.example:springpractice:jar:1.0-SNAPSHOT
[INFO] \- org.springframework:spring-context:jar:4.3.7.RELEASE:compile
[INFO]    +- org.springframework:spring-aop:jar:4.3.7.RELEASE:compile
[INFO]    +- org.springframework:spring-beans:jar:4.3.7.RELEASE:compile
[INFO]    +- org.springframework:spring-core:jar:4.3.7.RELEASE:compile
[INFO]    |  \- commons-logging:commons-logging:jar:1.2:compile
[INFO]    \- org.springframework:spring-expression:jar:4.3.7.RELEASE:compile