当Maven依赖插件位于

问题:

我们进行了一个集成测试,该测试创建了一个Spring ClassPathXmlApplicationContext ,同时这样做导致NoSuchMethodError爆炸。 事实证明,我们对Spring构件的依赖版本存在冲突。 这本身不是一个不寻常的问题-使用Maven依赖插件使用verbose选项解决了这些问题。 但是,当Maven插件错误时,您该怎么办?

调查:

我们开始深入研究,发现AbstractAutowireCapableBeanFactorygetTypeForFactoryMethod方法尝试访问GenericTypeResolver resolveReturnTypeForGeneric方法,并在java.lang.NoSuchMethodError: org.springframework.core.GenericTypeResolver.resolveReturnTypeForGenericMethod(Ljava/lang/reflect/Method;

初步调查和谷歌搜索发现,该方法是在3.2.0中添加的,而我们应该在3.1.1中运行。 进一步的调查确定spring-data-mongodb依赖于范围[3.0.7-4) 1的 spring框架,并且由于maven在给定范围2的情况下采用了最新的可用版本,因此它尝试采用3.2.2。
注意,在显式版本依赖项和范围依赖项之间存在冲突的情况下,上述更改有所变化,但是IINM在确定spring mongo的依赖项时没有冲突。

该问题被两个症状进一步掩盖:

  1. 我们还有其他使用这种模式的项目,没有问题-这可以通过以下事实来解释:Maven的冲突解决机制选择默认情况下找到的最近版本3 ,因为所有其他需要spring-data-mongodb的项目都依赖于这个项目他们很幸运地抢到了3.1.1版本而不是3.2.2
  2. dependency:tree显示它带来了3.1.1,而带来了3.2.2-因为堆栈跟踪显示了其他结果,所以我编写了一个测试,检查上述每个类来自哪个jar,并验证了AbstractAutowireCapableBeanFactory类确实来自spring-beans 3.2.2而不是3.1.1,如“ mvndependency:tree”所示(非常感谢http://bit.ly/10zD1iV提供了在运行时查找类的jar的代码段)。

Maven依赖项:在构件中使用显示spring-beans:3.1.1的树输出

&gt:mvn dependency:tree -Dverbose -Dincludes=org.springframework
...
(omitted for clarity)
...
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ wix-feature-toggle-administration ---
[INFO] artifact org.springframework:spring-beans: checking for updates from central
[INFO] artifact org.springframework:spring-beans: checking for updates from snapshots
[INFO] artifact org.springframework:spring-expression: checking for updates from central
[INFO] artifact org.springframework:spring-expression: checking for updates from snapshots
[INFO] artifact org.springframework:spring-tx: checking for updates from central
[INFO] artifact org.springframework:spring-tx: checking for updates from snapshots
[INFO] com.wixpress.common:wix-feature-toggle-administration:jar:2.180.0-SNAPSHOT
...
[INFO] +- org.springframework.data:spring-data-mongodb:jar:1.0.1.RELEASE:compile
[INFO] |  +- org.springframework:spring-beans:jar:3.1.1.RELEASE:compile
[INFO] |  |  \- (org.springframework:spring-core:jar:3.2.2.RELEASE:compile - omitted for conflict with 3.1.1.RELEASE)
[INFO] |  +- org.springframework:spring-expression:jar:3.1.1.RELEASE:compile
[INFO] |  |  \- (org.springframework:spring-core:jar:3.2.2.RELEASE:compile - omitted for conflict with 3.1.1.RELEASE)
[INFO] |  \- org.springframework.data:spring-data-commons-core:jar:1.2.1.RELEASE:compile
[INFO] |     +- (org.springframework:spring-beans:jar:3.1.1.RELEASE:compile - omitted for duplicate)
[INFO] |     \- (org.springframework:spring-tx:jar:3.1.1.RELEASE:compile - omitted for duplicate)
[INFO] +- com.wixpress.common:wix-framework:jar:2.180.0-SNAPSHOT:compile
[INFO] |  +- org.springframework:spring-core:jar:3.1.1.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-asm:jar:3.1.1.RELEASE:compile
...
I've removed additional outputs for clarity. The additional outputs were all 3.1.1 and were further down the tree (so irrelevant due to maven conflict resolving mechanism)

工件中使用了证明spring-beans:3.2.2的测试(断言错误中的jvm在说什么)

package com.wixpress.springVersionBug;import org.junit.*;
import org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory;
import org.springframework.core.GenericTypeResolver;
import java.security.CodeSource;
import static org.hamcrest.Matchers.endsWith;/*** @author ittaiz* @since 3/24/13*/public class SpringVersionTest {@Testpublic void verifySpringBeans311InClasspath(){verifyCorrectSpringVersionInClasspathFor(AbstractAutowireCapableBeanFactory.class,"spring-beans-3.1.1.RELEASE.jar");}@Testpublic void verifySpringCore311InClasspath(){verifyCorrectSpringVersionInClasspathFor(GenericTypeResolver.class,"spring-core-3.1.1.RELEASE.jar");}public void verifyCorrectSpringVersionInClasspathFor(Class springClass,String expectedJarFileName){CodeSource springClassCodeSource = springClass.getProtectionDomain().getCodeSource();Assert.assertNotNull("expecting "+expectedJarFileName+" to be loaded by non-system class loader",springClassCodeSource);Assert.assertThat(springClassCodeSource.getLocation().toString(),endsWith(expectedJarFileName));}
}

spring-beans成为3.2.2时, spring-core工件出现在3.1.1中的原因是我们的框架显式依赖于spring-core而该工件显式依赖于框架。 这意味着来自框架的spring-core 3.1.1是2跳,比来自spring-data-mongodb的3.2.2短。

解:

依赖spring-data-mongodb同时像这样排除spring-beans

<dependency><groupId>org.springframework.data</groupId><artifactId>spring-data-mongodb</artifactId><version>1.0.1.RELEASE</version><exclusions><exclusion><groupId>org.springframework</groupId><artifactId>spring-beans</artifactId></exclusion></exclusions>
</dependency>

开放问号:

为什么dependency:tree(在详细模式下)没有显示在3.2.2中而是在3.1.1中显示spring-beans,同时明确指定由于冲突而删除了spring-core 3.2.2? 我将此归结为依赖项插件中的错误。

  1. http://repo1.maven.org/maven2/org/springframework/data/spring-data-mongodb-parent/1.0.1.RELEASE/spring-data-mongodb-parent-1.0.1.RELEASE.pom ↩
  2. http://www.maestrodev.com/better-builds-with-maven/creating-applications-with-maven/resolving-dependency-conflicts-and-using-version-ranges/ ↩
  3. http://www.maestrodev.com/better-builds-with-maven/creating-applications-with-maven/resolving-dependency-conflicts-and-using-version-ranges/ ↩

参考: 当 Wix IO博客上的Maven依赖插件来自我们的JCG合作伙伴 Yoav Abrahami时。

翻译自: https://www.javacodegeeks.com/2013/04/when-maven-dependency-plugin-lies.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/368969.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

sql查询语句for xml path语法

【原地址】 for xml path作用&#xff1a;将多行的查询结果&#xff0c;根据某一些条件合并到一行。 例&#xff1a;现有一张表 执行下面语句 select Department,(SELECT Employee, FROM People b WHERE b.Departmenta.Department For XML Path()) Student from People as a g…

css高度已知,左右定宽,中间自适应三栏布局

css高度已知&#xff0c;左右定宽&#xff0c;中间自适应三栏布局&#xff1a; <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale…

java使用impala存放多条sql_Impala基于内存的SQL引擎的详细介绍

数据存储使用相同的存储数据池都支持把数据存储于HDFS, HBase。元数据&#xff1a;两者使用相同的元数据SQL解释处理&#xff1a;比较相似都是通过词法分析生成执行计划。执行计划&#xff1a;Hive: 依赖于MapReduce执行框架&#xff0c;执行计划分成 map->shuffle->redu…

Android Studio打包以及Gradle配置构建

本文转载 郭霖公众号 https://mp.weixin.qq.com/s?__bizMzA5MzI3NjE2MA&mid2650241610&idx1&snb8af73f6c288b6617d9fe0ab3618118d&pass_ticketQK4j37kpmGNlsYcECWMb64HxKHEVJG5mSJubQEQguKI%3D 生成签名文件手动打包 首先生成签名文件&#xff0c;点击 Build…

去除inline-block间隙的几种方法

为什么会产生间隙&#xff1f; 由于编写代码时的美观和可读性&#xff0c;在代码中添加回车或空格而产生的间隙。 html代码&#xff1a; <ul class"container"><li></li><li></li><li></li><li></li><li&…

java重载方法math_Java语言程序设计(十二)Math数学类,方法重载及变量作用域...

1.重载方法上一篇文章用到的max方法只能用于int型数据类型&#xff0c;但是如果需要决定两个浮点数中哪个较大&#xff0c;解决方法是创建另一个方法名相同但参数不同的方法&#xff0c;代码如下&#xff1a;public static double max(double num1, double num2){if(num1>nu…

编码(转)

https://www.zhihu.com/question/28164512 关于编码和乱码的问题&#xff0c;我简单讲一下。 通常问这类问题的人是混淆了若干个不同的概念&#xff0c;并且他们自己也没有意识到自己混淆了这些概念的。 终端显示字符的编码&#xff08;windows下终端是cmd&#xff0c;linux下是…

Spring MVC:测试简介

测试是软件开发中最重要的部分之一。 井井有条的测试有助于使应用程序代码保持良好状态&#xff0c;并且处于工作状态。 有很多不同类型的测试和方法。 在本文中&#xff0c;我想对基于Spring MVC的应用程序进行单元测试进行介绍。 不要希望在这里阅读有关Spring MVC测试的全部…

yaml,json,ini这三种格式用来做配置文件优缺点

适合人类编写&#xff1a;ini > toml > yaml > json > xml > plist可以存储的数据复杂度&#xff1a;xml > yaml > toml ~ json ~ plist > ini 作者&#xff1a;赵扶摇链接&#xff1a;https://www.zhihu.com/question/41253282/answer/119857880来源&…

试验ConcurrentHashmap

我正在研究我最近的一个项目中的内存问题&#xff0c;该项目将数据保留在内存中以进行快速访问&#xff0c;但是应用程序的内存占用量非常大。 该应用程序大量使用CHM&#xff08;即Concurrenthashmap&#xff09; &#xff0c;因此&#xff0c;无需再费脑筋地猜测CHM是问题所…

CSS的position属性:relative和absolute

relative&#xff1a;是相对于自己来定位的&#xff0c;例如&#xff1a;#demo{position:relative;top:-50px;},这时#demo会在相对于它原来的位置上移50px。如果它之前的元素也为relative并有偏移&#xff0c;则两个偏移不想加&#xff0c;relative只在它原本所在位置上进行偏移…

java线程池任务失败_ThreadPoolExecutor线程池任务执行失败的时候会怎样

1. 任务执行失败时的处理逻辑1.1. WorkerWorker相当于线程池中的线程可以看到&#xff0c;Worker有几个重要的属性&#xff1a;thread &#xff1a; 这是Worker运行的线程&#xff0c;可以理解为一个Worker就是一个线程firstTask &#xff1a; 初始任务&#xff0c;可能为为n…

转:HttpModule与HttpHandler详解

ASP.NET对请求处理的过程&#xff1a;当请求一个*.aspx文件的时候&#xff0c;这个请求会被inetinfo.exe进程截获&#xff0c;它判断文件的后缀&#xff08;aspx&#xff09;之后&#xff0c;将这个请求转交给 ASPNET_ISAPI.dll&#xff0c;ASPNET_ISAPI.dll会通过http管道&…

bzoj 5248: [2018多省省队联测]一双木棋

Description 菲菲和牛牛在一块n行m列的棋盘上下棋&#xff0c;菲菲执黑棋先手&#xff0c;牛牛执白棋后手。棋局开始时&#xff0c;棋盘上没有任何棋子&#xff0c; 两人轮流在格子上落子&#xff0c;直到填满棋盘时结束。落子的规则是&#xff1a;一个格子可以落子当且仅当这个…

java 数据返回类_java返回数据工具类

1 importcom.qbskj.project.util.SpringUtils;23 /**4 * 消息5 *6 */7 public classMessage {89 /**10 * 类型11 */12 public enumType {1314 /**成功*/15 success,1617 /**警告*/18 warn,1920 /**错误*/21 error22 }2324 /**类型*/25 privateType type;2627 /**内容*/28 priva…

MOXy的对象图和动态JAXB

JAXB&#xff08;JSR-222&#xff09;使您可以轻松地将域类的实例转换为XML。 EclipseLink MOXy实现提供了一个称为Dynamic JAXB的扩展&#xff0c;在其中&#xff0c;您没有像真实类那样的映射实例&#xff0c;例如名为DynamicEntity的类。 您可以使用采用属性名称的get和set方…

Processing-Shader-Examples

https://github.com/genekogan/Processing-Shader-Examples 转载于:https://www.cnblogs.com/guochen/p/7681278.html

随记

pip list 查看python所有的安装软件 pip uninstall 卸载 pip3 install 安装 pip install pip -V 查看pip版本 pip install --upgrade pip 对pip升级转载于:https://www.cnblogs.com/zqxqx/p/8906206.html

mysql时间函数总结_MySQL 日期时间函数常用总结

获得当前日期时间(date time)1.1 函数&#xff1a;now()相关函数&#xff1a;current_timestamp()&#xff0c;localtime()&#xff0c;localtimestamp()举例说明&#xff1a;2. 获得当前日期(date)函数&#xff1a;curdate()相关函数&#xff1a;current_date()&#xff0…

Apache CXF – JAX-WS –简单教程

许多Java开发人员认为Web Service实现的任务艰巨-没人能真正责怪他们&#xff0c;尤其是在企业应用程序开发的多年中&#xff0c;这给开发和设计带来了很多复杂性。 对于某些人来说&#xff0c;了解它是构建完整的企业应用程序的下一步-Web服务-是实现面向服务设计的关键方案之…