我有一个非常糟糕的问题-三个项目A,B,C。C的版本为1.0.5。我想用这个。A和B都已在其POMS中明确定义了此依赖版本。但是,在运行时,它们使用1.0.2。
它们都共享一个R根POM,但这应该无关紧要。
传奇:
当我运行项目A的main()时,它将尝试初始化spring上下文,该上下文会导入B上下文,而B上下文又包括C上下文。在1.0.2版中,C上下文包括B上下文,这导致了周期性的导入异常,如下所示:
例外:
Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath*:persistenceApplicationContext.xml]
Offending resource: class path resource [portletsApplicationContext.xml]; nested exception is org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath*:textProcessingApplicationContext.xml]
Offending resource: URL [jar:file:/C:/Users/Simon/.m2/repository/com/myProject/PersistenceModule/1.2.6-SNAPSHOT/PersistenceModule-1.2.6-SNAPSHOT.jar!/persistenceApplicationContext.xml]; nested exception is org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath*:persistenceApplicationContext.xml]
Offending resource: URL [jar:file:/C:/Users/Simon/.m2/repository/myProject/TextProcessing/1.0.2/TextProcessing-1.0.2.jar!/textProcessingApplicationContext.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Detected cyclic loading of URL [jar:file:/C:/Users/Simon/.m2/repository/com/myProject/PersistenceModule/1.2.6-SNAPSHOT/PersistenceModule-1.2.6-SNAPSHOT.jar!/persistenceApplicationContext.xml] - check your import definitions!
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:70)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:76)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:235)
........
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.myProject.myProject.portlets.demo.SolrStatementTest.main(SolrStatementTest.java:27)
Caused by: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath*:textProcessingApplicationContext.xml]
Offending resource: URL [jar:file:/C:/Users/Simon/.m2/repository/com/myProject/PersistenceModule/1.2.6-SNAPSHOT/PersistenceModule-1.2.6-SNAPSHOT.jar!/persistenceApplicationContext.xml]; nested exception is org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath*:persistenceApplicationContext.xml]
Offending resource: URL [jar:file:/C:/Users/Simon/.m2/repository/myProject/TextProcessing/1.0.2/TextProcessing-1.0.2.jar!/textProcessingApplicationContext.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Detected cyclic loading of URL [jar:file:/C:/Users/Simon/.m2/repository/com/myProject/PersistenceModule/1.2.6-SNAPSHOT/PersistenceModule-1.2.6-SNAPSHOT.jar!/persistenceApplicationContext.xml] - check your import definitions!
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:70)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:76)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:235)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseDefaultElement(DefaultBeanDefinitionDocumentReader.java:186)
at
..........
org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:216)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:229)
... 20 more
Caused by: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath*:persistenceApplicationContext.xml]
Offending resource: URL [jar:file:/C:/Users/Simon/.m2/repository/myProject/TextProcessing/1.0.2/TextProcessing-1.0.2.jar!/textProcessingApplicationContext.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Detected cyclic loading of URL [jar:file:/C:/Users/Simon/.m2/repository/com/myProject/PersistenceModule/1.2.6-SNAPSHOT/PersistenceModule-1.2.6-SNAPSHOT.jar!/persistenceApplicationContext.xml] - check your import definitions!
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:70)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:76)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:235)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseDefaultElement(DefaultBeanDefinitionDocumentReader.java:186)
... 31 more
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Detected cyclic loading of URL [jar:file:/C:/Users/Simon/.m2/repository/com/myProject/PersistenceModule/1.2.6-SNAPSHOT/PersistenceModule-1.2.6-SNAPSHOT.jar!/persistenceApplicationContext.xml] - check your import definitions!
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:326)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
... 42 more
一个(portlet)POM:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<url>http://maven.apache.org</url>
<name>portlets</name>
<groupId>
com.myProject</groupId>
<artifactId>portlets</artifactId>
<packaging>war</packaging>
<version>0.1.1-SNAPSHOT</version>
<properties>
<liferay.version>6.2.1</liferay.version>
<hibernate.version>4.2.13.Final</hibernate.version>
</properties>
<parent>
<groupId>
com.myProject</groupId>
<artifactId>myProjectRoot</artifactId>
<version>0.10</version>
</parent>
<scm>
<developerConnection>scm:svn:https://myProject.com/scm/svn/portlets/portlets</developerConnection>
</scm>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<tagBase>https://myProject.com/scm/svn/portlets/tags</tagBase>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
... many dependencies here
<!-- ============== myProject MODULES ============== -->
<dependency>
<groupId>com.myProject</groupId>
<artifactId>PersistenceModule</artifactId>
<version>1.2.6-SNAPSHOT</version>
<type>jar</type>
<exclusions>
<exclusion>
<artifactId>javaee-web-api</artifactId>
<groupId>javax</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.myProject</groupId>
<artifactId>EntityModule</artifactId>
<version>1.6</version>
<type>jar</type>
<exclusions>
<exclusion>
<artifactId>javaee-web-api</artifactId>
<groupId>javax</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.myProject</groupId>
<artifactId>Translator</artifactId>
<version>1.0.1</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.myProject</groupId>
<artifactId>Tagger</artifactId>
<version>1.0.3</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.myProject.utils</groupId>
<artifactId>WordNetUtil</artifactId>
<version>1.3</version>
<type>jar</type>
</dependency>
</dependencies>
</project>
B POM:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<url>http://maven.apache.org</url>
<name>PersistenceModule</name>
<groupId>com.myProject</groupId>
<artifactId>PersistenceModule</artifactId>
<version>1.2.6-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>com.myProject</groupId>
<artifactId>myProjectRoot</artifactId>
<version>0.10</version>
</parent>
<scm>
<developerConnection>scm:svn:https://myProject.com/scm/svn/persistence/PersistenceModule</developerConnection>
</scm>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.5</version>
<configuration>
<excludes>
<exclude>**/ratedPosts/**</exclude>
<exclude>**/testingMaterial/**</exclude>
<exclude>**/tempmyProjectFLD/**</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<configuration>
<excludes>
<exclude>**/ratedPosts/**</exclude>
<exclude>**/testingMaterial/**</exclude>
<exclude>**/tempmyProjectFLD/**</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<tagBase>https://myProject.com/scm/svn/persistence/tags</tagBase>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- MONGO -->
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
</dependency>
<!-- utils -->
<dependency>
<groupId>net.sf.opencsv</groupId>
<artifactId>opencsv</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<!-- mail -->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</dependency>
<dependency>
<groupId>com.myProject.harvest.utils</groupId>
<artifactId>java-libpst</artifactId>
</dependency>
<!-- Java -->
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<type>jar</type>
</dependency>
<dependency>
<groupId>myProject</groupId>
<artifactId>TextProcessing</artifactId>
<version>1.0.5</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
</dependency>
<!-- myProject -->
<dependency>
<groupId>com.myProject</groupId>
<artifactId>EntityModule</artifactId>
<version>1.6</version>
</dependency>
<!-- SPRING-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<!-- test -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<!-- Parsing -->
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-parsers</artifactId>
</dependency>
<!-- Social Network libs -->
<dependency>
<groupId>com.restfb</groupId>
<artifactId>restfb</artifactId>
</dependency>
</dependencies>
</project>
C POM:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>TextProcessing</name>
<url>http://maven.apache.org</url>
<groupId>myProject</groupId>
<artifactId>TextProcessing</artifactId>
<version>1.0.6-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>com.myProject</groupId>
<artifactId>myProjectRoot</artifactId>
<version>0.10</version>
</parent>
<scm>
<developerConnection>scm:svn:https://myProject.com/scm/svn/utils-translation/TextProcessing/trunk</developerConnection>
</scm>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.myProject</groupId>
<artifactId>Tagger</artifactId>
<version>1.0.3</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.myProject</groupId>
<artifactId>Translator</artifactId>
<version>1.0.1</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.myProject</groupId>
<artifactId>EntityModule</artifactId>
<type>jar</type>
<version>1.6</version>
<exclusions>
<exclusion>
<artifactId>javaee-web-api</artifactId>
<groupId>javax</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<type>jar</type>
</dependency>
</dependencies>
</project>
R(根)POM:被所有其他pom继承。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>myProjectRoot</name>
<groupId>com.myProject</groupId>
<artifactId>myProjectRoot</artifactId>
<version>0.11-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<powermock.version>1.5.6</powermock.version>
<spring.version>4.1.1.RELEASE</spring.version>
<spring.data.version>1.6.1.RELEASE</spring.data.version>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<hibernate.version>4.3.6.Final</hibernate.version>
</properties>
<!-- NEXUS configuration -->
<distributionManagement>
<repository>
<id>nexus</id>
<name>Releases</name>
<url>https://myProject.com/nexus/content/repositories/releases/</url>
<layout>default</layout>
</repository>
<snapshotRepository>
<id>nexus</id>
<name>Snapshots</name>
<url>https://myProject.com/nexus/content/repositories/snapshots/</url>
<layout>default</layout>
</snapshotRepository>
</distributionManagement>
<scm>
<developerConnection>scm:svn:https://myProject.com/scm/svn/myProjectroot/trunk</developerConnection>
</scm>
<build>
<!-- Global settings of maven plugins across myProject. Can be overriden with custom plugin managment, not recommended. -->
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<!-- <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
</plugin>-->
</plugins>
</build>
<!-- Used for setting global versions of projects used across myProject.
In your project only declare groupId and artifactId to use a dependency with
a version and configuration used in this pom. -->
<dependencyManagement>
<dependencies>
................................ many more..................
<!-- myProject DEPENDENCIES -->
<dependency>
<groupId>com.myProject</groupId>
<artifactId>EntityModule</artifactId>
<version>1.4.1-SNAPSHOT</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.myProject</groupId>
<artifactId>PersistenceModule</artifactId>
<version>1.2.3</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.myProject.analysis</groupId>
<artifactId>ContentModule</artifactId>
<version>1.2-SNAPSHOT</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>myProject</groupId>
<artifactId>TextProcessing</artifactId>
<version>1.0.5</version>
<type>jar</type>
</dependency>
<!-- harvests -->
<dependency>
<groupId>com.myProject</groupId>
<artifactId>DocumentHarvest</artifactId>
<version>1.0.1</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.myProject</groupId>
<artifactId>harvest-Twitter</artifactId>
<version>1.0</version>
<type>jar</type>
</dependency>
</dependencies>
</dependencyManagement>
</project>
我注意到,即使我正在使用的特定快照中的pom包含1.0.5 C依赖关系,它仍然表明正在使用的传递导入依赖关系是1.0.2。看截图:您可以在图像上看到TextProcessing 1.0.2是VIA PersistenceModule。但是,所使用的依赖项(它的pom已打开)的依赖项设置为1.0.5。我从依赖关系树而不是从项目本身打开POM,以确保我真的在查看特别使用的快照的依赖关系。
所以问题是,在我的父pom中,使用的(0.10)是定义为1.0.2的C项目。
A项目有B,在1.0.5中引用了C,因此可传递性A应该在1.0.5中具有C,但是,A从R(从Parent / Root)那里获得了C版本1.0.2。显然,它具有更高的优先级。可能是因为maven依赖于依赖版本,直到依赖版本到达依赖版本为止。选择的最小深度(第一次命中)是1.0.2,这是我的问题。
解决方案是我首先应该做的-从父级删除我自己的模块。现在,它会过渡性地采用好版本。
我在某处读到,将自己的模块放在父级中以解析它们之间的版本是一种不好的做法。经过很长一段时间,我实际上是通过经验找到原因,为什么这是一种不好的做法。
感谢@sorencito提供有关使用mvndependency:tree进行检查的建议。它向我展示了一个结构,该结构帮助我搜索了这个堆栈溢出问题,这使我想到了旧的父版本。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句