Maven依赖Spring类路径问题

时间:2012-01-20 15:16:19

标签: spring maven dependencies classpath

所以基本上使用下面显示的pom,我最终在我的WEB-INF / lib文件夹中有两个版本的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。

2 个答案:

答案 0 :(得分:3)

尝试跑步:

$ 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

现在你知道<exclusion>里面有什么了。另一种方法是删除所有排除项,并简单地在新版本中明确声明依赖项,这将覆盖传递依赖项:

    <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,它会指导您。

答案 1 :(得分: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