日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

当Maven依赖插件位于

發布時間:2023/12/3 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 当Maven依赖插件位于 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

問題:

我們進行了一個集成測試,該測試創建了一個Spring ClassPathXmlApplicationContext ,同時這樣做導致NoSuchMethodError爆炸。 事實證明,我們對Spring構件的依賴版本存在沖突。 這本身不是一個不尋常的問題-使用Maven依賴插件使用verbose選項解決了這些問題。 但是,當Maven插件錯誤時,您該怎么辦?

調查:

我們開始深入研究,發現AbstractAutowireCapableBeanFactory的getTypeForFactoryMethod方法嘗試訪問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的依賴項時沒有沖突。

該問題被兩個癥狀進一步掩蓋:

  • 我們還有其他使用這種模式的項目,沒有問題-這可以通過以下事實來解釋:Maven的沖突解決機制選擇默認情況下找到的最近版本3 ,因為所有其他需要spring-data-mongodb的項目都依賴于這個項目他們很幸運地搶到了3.1.1版本而不是3.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? 我將此歸結為依賴項插件中的錯誤。

  • 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 ?
  • http://www.maestrodev.com/better-builds-with-maven/creating-applications-with-maven/resolving-dependency-conflicts-and-using-version-ranges/ ?
  • 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

    總結

    以上是生活随笔為你收集整理的当Maven依赖插件位于的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。