java 如何升级所有 spring 依赖项?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27795677/
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-11-02 12:24:17  来源:igfitidea点击:

How to upgrade ALL the spring dependency?

javaspringmaven

提问by smwikipedia

I have a spring-webmvc based web application. It used the org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializerwhich is not supported by the spring version used in my project.

我有一个基于 spring-webmvc 的 Web 应用程序。它使用了org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer我的项目中使用的 spring 版本不支持的 。

My project's spring dependency look like this:

我的项目的 spring 依赖如下所示:

enter image description here

在此处输入图片说明

I want to upgrade all spring dependency from 3.1.1 to 4.1.2. How to do that?

我想将所有 spring 依赖项从 3.1.1 升级到 4.1.2。怎么做?

回答by Master Slave

You should move from a hardcoded version of a spring version inside a pom.xml to a property, e.g.

您应该从 pom.xml 内的弹簧版本的硬编码版本移动到属性,例如

inside your properties

在你的属性里面

 <springframework.version>4.0.2.RELEASE</springframework.version>

inside your dependencies

在您的依赖项中

<!-- spring -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>${springframework.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-expression</artifactId>
    <version>${springframework.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-beans</artifactId>
    <version>${springframework.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aop</artifactId>
    <version>${springframework.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>${springframework.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context-support</artifactId>
    <version>${springframework.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>${springframework.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-orm</artifactId>
    <version>${springframework.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>${springframework.version}</version>
</dependency>
<!-- spring security -->
<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-config</artifactId>
    <version>${springframework.security.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-core</artifactId>
    <version>${springframework.security.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-web</artifactId>
    <version>${springframework.security.version}</version>
</dependency>

with this setup its easy to migrate the versions, the listed deps are just copy/paste, don't take it for granted, use what you need

使用此设置可以轻松迁移版本,列出的 deps 只是复制/粘贴,不要想当然,使用您需要的

回答by user3145373 ツ

you can update dependency like this globally :

您可以像这样全局更新依赖项:

<properties>
        <spring.version>4.1.2.RELEASE</spring.version>
</properties>

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>${spring.version}</version>
</dependency>

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

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>${spring.version}</version>
</dependency>

using this global dependency version management, you can avoid some version compatibility exception.

使用这个全局依赖版本管理,你可以避免一些version compatibility exception.

回答by J2B

Since you are using Maven, your pom-dependencies will probably look like

由于您使用的是 Maven,因此您的 pom 依赖项可能看起来像

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

You could replace "3.1.1.RELEASE" with ${spring-version}, and add the following to your pom-file

您可以用 ${spring-version} 替换“3.1.1.RELEASE”,并将以下内容添加到您的 pom 文件中

<properties>
  <spring-version>4.1.2</spring-version>
</properties>

It will make it easier to change version for all your spring dependencies

这将使更改所有 spring 依赖项的版本变得更容易

回答by Ummer Iqbal

If you using maven build tool,so it's very simple to upgrade spring 3 to spring 4 you just open pom.xml file in the properties xml tag just change the version 3.x.x to 4 something. e.g:

如果您使用 maven 构建工具,那么将 spring 3 升级到 spring 4 非常简单,只需在属性 xml 标记中打开 pom.xml 文件,只需将版本 3.xx 更改为 4 即可。例如:

<org.springframework-version>3.0.2.RELEASE</org.springframework-version>

to

<org.springframework-version>4.0.2.RELEASE</org.springframework-version>