1

これは私のプロジェクトの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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>learn.spring</groupId>
    <artifactId>someProject</artifactId>
    <packaging>war</packaging>
    <version>1.0</version>
    <name>someProject</name>
    <url>http://maven.apache.org</url>
    <repositories>
        <repository>
            <id>maven2-repository.java.net</id>
            <name>Java.net Repository for Maven</name>
            <url>http://download.java.net/maven/2/</url>
            <layout>default</layout>
        </repository>
    </repositories>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <org.springframework.version>3.1.0.RELEASE</org.springframework.version>
        <org.slf4j.version>1.5.10</org.slf4j.version>
        <org.slf4j.version>1.5.10</org.slf4j.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>oro</groupId>
            <artifactId>oro</artifactId>
            <version>2.0.8</version>
        </dependency>

        <dependency>
            <groupId>commons-validator</groupId>
            <artifactId>commons-validator</artifactId>
            <version>1.3.1</version>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>

        </dependency>




        <!-- Jersey + Spring -->
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-server</artifactId>
            <version>1.8</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-json</artifactId>
            <version>1.8</version>
        </dependency>


        <dependency>
            <groupId>com.sun.jersey.contribs</groupId>
            <artifactId>jersey-spring</artifactId>
            <version>1.8</version>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-core</artifactId>
                </exclusion>

                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-aop</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-web</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-beans</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-context</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>net.sf.jasperreports</groupId>
            <artifactId>jasperreports</artifactId>
            <version>4.7.0</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <version>1.7-beta-1</version>
        </dependency>

        <!-- Log4j Dependency -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>1.5.8</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.5.8</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.5.8</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.14</version>
        </dependency>
        <!-- Postgres dependency -->
        <dependency>
            <groupId>postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>9.1-901.jdbc4</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>

        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>20030825.184428</version>
        </dependency>
        <dependency>
            <groupId>commons-pool</groupId>
            <artifactId>commons-pool</artifactId>
            <version>20030825.183949</version>
        </dependency>
        <dependency>
            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
            <version>20040616</version>
        </dependency>

        <!-- JSTL dependency -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <!-- Spring Web Support -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${org.springframework.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>

            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
    </dependencies>
    <build>
        <finalName>someProject</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.0-SNAPSHOT</version>
            </plugin>
        </plugins>
    </build>



</project>

ビルド パスで使用する Spring バージョン 3.1.0 を指定しましたが、Spring 3.0.5.RELEASE に自動的に変換されます。Spring + Jersey依存関係のせいだと思います。サーバーを起動しようとするとmvn tomcat:run、次の例外が発生します。

java.lang.NoClassDefFoundError: org/springframework/core/env/EnvironmentCapable
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
        at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1141)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1612)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
        at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1141)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1612)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)
        at java.lang.Class.getDeclaredConstructors0(Native Method)
        at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
        at java.lang.Class.getConstructor0(Class.java:2699)
        at java.lang.Class.newInstance0(Class.java:326)
        at java.lang.Class.newInstance(Class.java:308)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4079)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4630)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
        at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
        at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
        at org.apache.catalina.startup.Embedded.start(Embedded.java:825)
        at org.codehaus.mojo.tomcat.AbstractRunMojo.startContainer(AbstractRunMojo.java:558)
        at org.codehaus.mojo.tomcat.AbstractRunMojo.execute(AbstractRunMojo.java:255)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: java.lang.ClassNotFoundException: org.springframework.core.env.EnvironmentCapable
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491) 

EnvironmentCapable.class ファイルは にありますspring-core-3.1.0.RELEASE.jar。手動で jar をビルド パスに追加しましたが、それでも同じ例外が発生します。私はエクリプスインディゴを使用しています。ご意見をお聞かせください。

4

3 に答える 3

4

pom.xml中を確認するとこんな感じjersey-spring-1.8.jar

    <properties>
        <spring20-release-version>2.0.5</spring20-release-version>
        <spring25-release-version>[2.5.2,3)</spring25-release-version>
    </properties>

つまり、jersey-spring-1.8 では、春のバージョンは 3 までしか使用できません。これが問題だと思います。

于 2012-12-27T07:14:57.243 に答える
1

はどこ<version>${org.springframework.version}</version>から来ているのですか?これは POM ファイルでプロパティとして定義されていないため、このプロパティは依存関係の 1 つに由来し、あなたの依存関係を引き継いでいると思います3.1.RELEASE(ヒント: jersey-spring の依存関係を見てください) バージョンの定義にプロパティを使用しないでください! 暗黙的および明示的なバージョンを制御するには、 Maven の < DependencyManagement > セクションを使用してください。依存スコープを使用することをお勧めしますprovided

于 2012-12-27T07:17:56.013 に答える
0

問題は、POM の LDAP 依存関係にありました。3.0.5 バージョンをビルド パスに統合していました。mvn dependency:treeそれが明らかになりました。

 learn.spring:someProject:war:1.0
 +- junit:junit:jar:3.8.1:test (scope not updated to compile)
 +- oro:oro:jar:2.0.8:compile
 +- commons-validator:commons-validator:jar:1.3.1:compile
 |  +- commons-beanutils:commons-beanutils:jar:1.7.0:compile
 |  \- commons-digester:commons-digester:jar:1.6:compile
 +- org.springframework.ldap:spring-ldap-core:jar:1.3.1.RELEASE:compile
 |  +- commons-logging:commons-logging:jar:1.0.4:compile
 |  +- commons-lang:commons-lang:jar:2.5:compile
 |  +- org.springframework:spring-core:jar:3.0.5.RELEASE:compile
 |  +- org.springframework:spring-beans:jar:3.0.5.RELEASE:compile
 |  \- org.springframework:spring-tx:jar:3.0.5.RELEASE:compile
 +- com.sun.jersey:jersey-server:jar:1.8:compile
 |  +- asm:asm:jar:3.1:compile
 |  \- com.sun.jersey:jersey-core:jar:1.8:compile
 +- com.sun.jersey:jersey-json:jar:1.8:compile
 |  +- org.codehaus.jettison:jettison:jar:1.1:compile
 |  |  \- stax:stax-api:jar:1.0.1:compile
 |  +- com.sun.xml.bind:jaxb-impl:jar:2.2.3-1:compile
 |  |  \- javax.xml.bind:jaxb-api:jar:2.2.2:compile
 |  |     +- javax.xml.stream:stax-api:jar:1.0-2:compile
 |  |     \- javax.activation:activation:jar:1.1:compile
 |  +- org.codehaus.jackson:jackson-core-asl:jar:1.7.1:compile
 |  +- org.codehaus.jackson:jackson-mapper-asl:jar:1.7.1:compile
 |  +- org.codehaus.jackson:jackson-jaxrs:jar:1.7.1:compile
 |  \- org.codehaus.jackson:jackson-xc:jar:1.7.1:compile
 +- com.sun.jersey.contribs:jersey-spring:jar:1.8:compile
 +- javax.servlet:javax.servlet-api:jar:3.0.1:provided
 +- net.sf.jasperreports:jasperreports:jar:4.7.0:compile
 |  +- com.lowagie:itext:jar:2.1.7:compile
 |  |  +- bouncycastle:bcmail-jdk14:jar:138:compile
 |  |  +- bouncycastle:bcprov-jdk14:jar:138:compile
 |  |  \- org.bouncycastle:bctsp-jdk14:jar:1.38:compile
 |  |     +- org.bouncycastle:bcprov-jdk14:jar:1.38:compile
 |  |     \- org.bouncycastle:bcmail-jdk14:jar:1.38:compile
 |  +- jfree:jcommon:jar:1.0.15:compile
 |  +- jfree:jfreechart:jar:1.0.12:compile
 |  +- xml-apis:xml-apis:jar:1.3.02:compile
 |  +- eclipse:jdtcore:jar:3.1.0:compile
 |  +- org.codehaus.castor:castor:jar:1.2:compile
 |  \- org.apache.poi:poi-ooxml:jar:3.7:compile
 |     +- org.apache.poi:poi:jar:3.7:compile
 |     +- org.apache.poi:poi-ooxml-schemas:jar:3.7:compile
 |     |  +- org.apache.xmlbeans:xmlbeans:jar:2.3.0:compile
 |     |  \- org.apache.geronimo.specs:geronimo-stax-api_1.0_spec:jar:1.0:compile
 |     \- dom4j:dom4j:jar:1.6.1:compile
 +- org.codehaus.groovy:groovy-all:jar:1.7-beta-1:compile
 |  +- org.apache.ant:ant:jar:1.7.1:compile
 |  |  \- org.apache.ant:ant-launcher:jar:1.7.1:compile
 |  \- jline:jline:jar:0.9.94:compile
 +- org.slf4j:jcl-over-slf4j:jar:1.5.8:runtime
 +- org.slf4j:slf4j-api:jar:1.5.8:runtime
 +- org.slf4j:slf4j-log4j12:jar:1.5.8:runtime
 +- log4j:log4j:jar:1.2.14:compile
 +- postgresql:postgresql:jar:9.1-901.jdbc4:compile
 +- org.springframework:spring-jdbc:jar:3.1.0.RELEASE:compile
 +- commons-dbcp:commons-dbcp:jar:20030825.184428:compile
 +- commons-pool:commons-pool:jar:20030825.183949:compile
 +- commons-collections:commons-collections:jar:20040616:compile
 +- javax.servlet:jstl:jar:1.2:compile
 +- org.springframework:spring-web:jar:3.1.0.RELEASE:compile
 |  +- aopalliance:aopalliance:jar:1.0:compile
 |  \- org.springframework:spring-context:jar:3.1.0.RELEASE:compile
 |     \- org.springframework:spring-expression:jar:3.1.0.RELEASE:compile
 \- org.springframework:spring-aop:jar:3.1.0.RELEASE:compile
    \- org.springframework:spring-asm:jar:3.1.0.RELEASE:compile

上記のaviadが示唆したようにprovided、LDAP 依存関係への追加は正常に機能しました。exclusionsかなり面倒な依存関係に追加しました。:)

<dependency>
            <groupId>org.springframework.ldap</groupId>
            <artifactId>spring-ldap-core</artifactId>
            <version>1.3.1.RELEASE</version>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-core</artifactId>
                </exclusion>

                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-aop</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-web</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-beans</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-context</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-tx</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
于 2012-12-27T10:51:07.773 に答える