【问题标题】:Maven Dependency Spring Classpath IssueMaven 依赖 Spring 类路径问题
【发布时间】:2012-02-15 03:31:11
【问题描述】:

所以基本上使用下面显示的 pom,我最终在我的 WEB-INF/lib 文件夹中得到了 2 个版本的 Spring(3.1 和 3.0.5,甚至奇怪的是 3.0.6)。我假设 spring-ws 是造成这种情况的原因,所以我尝试添加排除项,以便它不会下载旧版本无济于事。有什么建议吗?

    <repositories>
        <repository>
            <id>repository.springframework.milestone</id>
            <name>Spring Framework Maven Milestone Repository</name>
            <url>http://maven.springframework.org/milestone</url>
        </repository>
    </repositories>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>  
            <groupId>com.sun.xml.messaging.saaj</groupId>  
            <artifactId>saaj-impl</artifactId>  
            <version>1.3</version>  
            <scope>runtime</scope>  
        </dependency>
        <dependency>
            <groupId>org.springframework.ws</groupId>
            <artifactId>spring-ws-core</artifactId>
            <version>2.0.3.RELEASE</version>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-aop</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-context</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-oxm</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-test</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-web</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-webmvc</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-core</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-beans</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>  
            <groupId>javax.xml.bind</groupId>  
            <artifactId>jaxb-api</artifactId>  
            <version>2.0</version>  
        </dependency>  
        <dependency>  
            <groupId>com.sun.xml.bind</groupId>  
            <artifactId>jaxb-impl</artifactId>  
            <version>2.0.3</version>  
        </dependency>  
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>3.1.0.RELEASE</version>
        </dependency>
    </dependencies>
    <build>
        <finalName>LicensingSOAPService</finalName>
        <plugins>
            <plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

编辑以在添加更多排除项后显示新的 pom。

【问题讨论】:

  • 是的,我在 mvnrepository 中看到 spring-ws 依赖于 spring jar,但这就是我添加排除项的原因。这不应该阻止这些其他版本被插入到我的 lib 文件夹中吗?

标签: spring maven dependencies classpath


【解决方案1】:

尝试运行:

$ mvn dependency:tree

这将揭示您当前配置中spring-ws 的以下有效依赖关系:

+- org.springframework.ws:spring-ws-core:jar:2.0.3.RELEASE:compile
|  +- org.springframework.ws:spring-xml:jar:2.0.3.RELEASE:compile
|  +- wsdl4j:wsdl4j:jar:1.6.1:compile
|  +- commons-logging:commons-logging:jar:1.1.1:compile
|  +- org.springframework:spring-core:jar:3.0.6.RELEASE:compile
|  \- org.springframework:spring-beans:jar:3.0.6.RELEASE:compile

现在你知道&lt;exclusion&gt; 里面有什么了。另一种方法是摆脱所有排除项,并在较新的版本中显式声明依赖项,这将覆盖传递依赖项:

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>3.1.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-oxm</artifactId>
        <version>3.1.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>3.1.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>3.1.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>3.1.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>3.1.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>3.1.0.RELEASE</version>
    </dependency>

再次尝试mvn dependency:tree,它将指导您。

【讨论】:

  • 好吧,我运行了它并且确实看到了这些依赖项,但即使将它们添加到排除项中,我仍然会得到 3.0.5 和 3.0.6 的 Spring jar 文件。依赖项列表中的任何其他内容都不依赖于 spring jar,因此它与 spring-ws 有关,但要么我缺少某些东西,要么它拒绝服从我并且不排除它自己的依赖项。编辑:我什至再次运行了 mvn 依赖项:树,并且在 spring-ws 下不再出现 spring jar。这些其他罐子是怎么被塞进去的?
  • Tomasz,如果您可以进一步详细说明我对依赖项所做的更多操作:tree 我很想尝试一下,但是到目前为止,当我运行命令时,没有列出更多的 spring jar,并且但是我的类路径中仍然有 3.0.5 和 3.0.6 的弹簧罐。
  • 如果您使用 Eclipse(带有 maven 插件),那么您可以拥有一个依赖关系树(pom 编辑器上的选项卡)。这将向您显示对此库的引用来自何处。
  • 现在试用 eclipse 插件。
  • 因此,即使在 Eclipse 中的依赖层次结构下,我也没有看到除 3.1 之外的任何弹簧罐。 maven 怎么可能将旧版本扫描到我的 lib 文件夹中?任何帮助都将非常感激。谢谢..!
【解决方案2】:

我在一个新项目中复制了你的 pom。并且没有 Spring 3.0.x 依赖!

所以你可能只有刷新问题。

mvn dependency:tree
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building test2 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ test2 ---
[INFO] test2:test2:jar:0.0.1-SNAPSHOT
[INFO] +- junit:junit:jar:3.8.1:test
[INFO] +- com.sun.xml.messaging.saaj:saaj-impl:jar:1.3:runtime
[INFO] |  \- javax.xml.soap:saaj-api:jar:1.3:runtime
[INFO] +- org.springframework.ws:spring-ws-core:jar:2.0.3.RELEASE:compile
[INFO] |  +- org.springframework.ws:spring-xml:jar:2.0.3.RELEASE:compile
[INFO] |  +- wsdl4j:wsdl4j:jar:1.6.1:compile
[INFO] |  \- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] +- javax.xml.bind:jaxb-api:jar:2.0:compile
[INFO] |  +- javax.xml.bind:jsr173_api:jar:1.0:compile
[INFO] |  \- javax.activation:activation:jar:1.1:compile
[INFO] +- com.sun.xml.bind:jaxb-impl:jar:2.0.3:compile
[INFO] \- org.springframework:spring-context:jar:3.1.0.RELEASE:compile
[INFO]    +- org.springframework:spring-aop:jar:3.1.0.RELEASE:compile
[INFO]    |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO]    +- org.springframework:spring-beans:jar:3.1.0.RELEASE:compile
[INFO]    +- org.springframework:spring-core:jar:3.1.0.RELEASE:compile
[INFO]    +- org.springframework:spring-expression:jar:3.1.0.RELEASE:compile
[INFO]    \- org.springframework:spring-asm:jar:3.1.0.RELEASE:compile

【讨论】:

    猜你喜欢
    • 2011-03-20
    • 1970-01-01
    • 1970-01-01
    • 2021-11-06
    • 2014-10-11
    • 2017-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多