2016-10-18 14 views
1

mongoDbをSpringのmongoTemplateに接続しようとしています。しかし、データベース上でCRUD操作を実行している間、私はjava.lang.NoSuchMethodError: org.springframework.data.mongodb.core.mapping.MongoPersistentEntity.hasVersionProperty()Zエラーjava.lang.NoSuchMethodError mongoDbをSpring経由で接続する際のエラー

を取得しています。ここに私のpom.xmlは

<!-- Spring framework --> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-core</artifactId> 
     <version>3.2.2.RELEASE</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-context</artifactId> 
     <version>3.2.2.RELEASE</version> 
     <exclusions> 
      <exclusion> 
       <groupId>org.springframework</groupId> 
       <artifactId>spring-core</artifactId> 
      </exclusion> 
      <exclusion> 
       <groupId>org.springframework</groupId> 
       <artifactId>spring-beans</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 

    <!-- mongodb java driver --> 
    <dependency> 
     <groupId>org.mongodb</groupId> 
     <artifactId>mongo-java-driver</artifactId> 
     <version>2.10.1</version> 
    </dependency> 

    <!-- Spring data mongodb --> 
    <dependency> 
     <groupId>org.springframework.data</groupId> 
     <artifactId>spring-data-mongodb</artifactId> 
     <version>1.2.0.RELEASE</version> 
     <exclusions> 
      <exclusion> 
       <groupId>org.mongodb</groupId> 
       <artifactId>mongo-java-driver</artifactId> 
      </exclusion> 
      <exclusion> 
       <groupId>org.springframework</groupId> 
       <artifactId>spring-core</artifactId> 
      </exclusion> 
      <exclusion> 
       <groupId>org.springframework</groupId> 
       <artifactId>spring-expression</artifactId> 
      </exclusion> 
      <exclusion> 
       <groupId>org.springframework</groupId> 
       <artifactId>spring-context</artifactId> 
      </exclusion> 
      <exclusion> 
       <groupId>org.springframework</groupId> 
       <artifactId>spring-aop</artifactId> 
      </exclusion> 
      <exclusion> 
       <groupId>aopalliance</groupId> 
       <artifactId>aopalliance</artifactId> 
      </exclusion> 
      <!-- <exclusion> 
       <groupId>org.slf4j</groupId> 
       <artifactId>slf4j-api</artifactId> 
      </exclusion> --> 
      <!-- <exclusion> 
       <groupId>org.slf4j</groupId> 
       <artifactId>jcl-over-slf4j</artifactId> 
      </exclusion> --> 
      <exclusion> 
       <artifactId>spring-beans</artifactId> 
       <groupId>org.springframework</groupId> 
      </exclusion> 
     </exclusions> 
    </dependency> 

    <dependency> 
     <groupId>cglib</groupId> 
     <artifactId>cglib</artifactId> 
     <version>2.2.2</version> 
    </dependency> 

</dependencies> 

<build> 
    <plugins> 
     <plugin> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>3.0</version> 
      <configuration> 
       <source>1.6</source> 
       <target>1.6</target> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-eclipse-plugin</artifactId> 
      <version>2.9</version> 
      <configuration> 
       <downloadSources>true</downloadSources> 
       <downloadJavadocs>true</downloadJavadocs> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

マイmongoconfigurationファイル

@Configuration 
public class SpringMongoConfig1 { 

    @Bean 
    MongoDbFactory mongoDbFactory() throws Exception{ 
     return new SimpleMongoDbFactory(new MongoClient(), "storeApp"); 
    } 

    @Bean 
    MongoTemplate mongoTemplate() throws Exception{ 
     MongoTemplate mongoTemplate = new MongoTemplate(mongoDbFactory()); 
     return mongoTemplate; 
    } 
} 

メインクラスですプロジェクト

public class StoreMainApp { 

    public static void main(String[] args) { 

     System.out.println("into main method"); 

     ApplicationContext ctx = new AnnotationConfigApplicationContext(SpringMongoConfig1.class); 
     MongoOperations mongoOperation = (MongoOperations)ctx.getBean("mongoTemplate"); 


     Store store1 = new Store("Sample store 1", "Street 1", "City 1", (float) 35.4); 
     System.out.println("store1 city : "+store1.storeCity); 


     mongoOperation.insert(store1); 
    } 
} 

私はmongoOperation.createCollection(「店舗」)を使用している場合;,それが正常に動作し、名前の店を持つコレクションがデータベースに作成されたばかり、しかしどのmongoOperation.save()またはmongoOperation.insert()メソッドではありませんランニング。スタックトレース後

:あなたは任意のjarファイルの競合がある場合mvn dependency:tree -Dverboseを発行

Exception in thread "main" java.lang.NoSuchMethodError: org.springframework.data.mongodb.core.mapping.MongoPersistentEntity.hasVersionProperty()Z 
     at org.springframework.data.mongodb.core.MongoTemplate.initializeVersionProperty(MongoTemplate.java:669) 
     at org.springframework.data.mongodb.core.MongoTemplate.doInsert(MongoTemplate.java:651) 
     at org.springframework.data.mongodb.core.MongoTemplate.insert(MongoTemplate.java:613) 
     at org.springframework.data.mongodb.core.MongoTemplate.insert(MongoTemplate.java:604) 
     at com.storeApp.core.StoreMainApp.main(StoreMainApp.java:33) 
+0

更新されたpom.xmlでプロジェクトをコンパイルしてもよろしいですか?私はそれを試してコンパイルエラーを出します。 – pleft

答えて

1

が明らかになります。私は、コマンドを自分で行っていると私はorg.springframework.data:spring-data-mongodb:jar:1.2.0.RELEASEにあなたが紛争中のjarファイルの同じバージョンを持っていることを確認するorg.mongodb:mongo-java-driver:jar:2.10.1

を参照しながら、あなたはバージョン2.11.0mongo-java-driverを持っていることがわかります。

[INFO] +- org.springframework:spring-core:jar:3.2.2.RELEASE:compile 
[INFO] | \- commons-logging:commons-logging:jar:1.1.1:compile 
[INFO] +- org.springframework:spring-context:jar:3.2.2.RELEASE:compile 
[INFO] | +- org.springframework:spring-aop:jar:3.2.2.RELEASE:compile 
[INFO] | | +- aopalliance:aopalliance:jar:1.0:compile 
[INFO] | | +- (org.springframework:spring-beans:jar:3.2.2.RELEASE:compile - omitted for duplicate) 
[INFO] | | \- (org.springframework:spring-core:jar:3.2.2.RELEASE:compile - omitted for duplicate) 
[INFO] | +- org.springframework:spring-beans:jar:3.2.2.RELEASE:compile 
[INFO] | | \- (org.springframework:spring-core:jar:3.2.2.RELEASE:compile - omitted for duplicate) 
[INFO] | +- (org.springframework:spring-core:jar:3.2.2.RELEASE:compile - omitted for duplicate) 
[INFO] | \- org.springframework:spring-expression:jar:3.2.2.RELEASE:compile 
[INFO] |  \- (org.springframework:spring-core:jar:3.2.2.RELEASE:compile - omitted for duplicate) 
[INFO] +- org.mongodb:mongo-java-driver:jar:2.11.0:compile 
[INFO] +- org.springframework.data:spring-data-mongodb:jar:1.2.0.RELEASE:compile 
[INFO] | +- org.springframework:spring-tx:jar:3.1.4.RELEASE:compile 
[INFO] | | +- (aopalliance:aopalliance:jar:1.0:compile - omitted for duplicate) 
[INFO] | | +- (org.springframework:spring-aop:jar:3.1.4.RELEASE:compile - omitted for conflict with 3.2.2.RELEASE) 
[INFO] | | +- (org.springframework:spring-beans:jar:3.1.4.RELEASE:compile - omitted for conflict with 3.2.2.RELEASE) 
[INFO] | | +- (org.springframework:spring-context:jar:3.1.4.RELEASE:compile - omitted for conflict with 3.2.2.RELEASE) 
[INFO] | | \- (org.springframework:spring-core:jar:3.1.4.RELEASE:compile - omitted for conflict with 3.2.2.RELEASE) 
[INFO] | +- (org.springframework:spring-context:jar:3.1.4.RELEASE:compile - omitted for conflict with 3.2.2.RELEASE) 
[INFO] | +- (org.springframework:spring-beans:jar:3.1.4.RELEASE:compile - omitted for conflict with 3.2.2.RELEASE) 
[INFO] | +- (org.springframework:spring-core:jar:3.1.4.RELEASE:compile - omitted for conflict with 3.2.2.RELEASE) 
[INFO] | +- (org.springframework:spring-expression:jar:3.1.4.RELEASE:compile - omitted for conflict with 3.2.2.RELEASE) 
[INFO] | +- org.springframework.data:spring-data-commons:jar:1.5.0.RELEASE:compile 
[INFO] | | +- (org.springframework:spring-core:jar:3.1.4.RELEASE:compile - omitted for conflict with 3.2.2.RELEASE) 
[INFO] | | +- (org.springframework:spring-beans:jar:3.1.4.RELEASE:compile - omitted for conflict with 3.2.2.RELEASE) 
[INFO] | | +- (org.slf4j:slf4j-api:jar:1.7.1:compile - omitted for conflict with 1.7.21) 
[INFO] | | \- (org.slf4j:jcl-over-slf4j:jar:1.7.1:runtime - omitted for conflict with 1.7.1) 
[INFO] | +- (org.mongodb:mongo-java-driver:jar:2.10.1:compile - omitted for conflict with 2.11.0) 
[INFO] | +- (org.slf4j:slf4j-api:jar:1.7.1:compile - omitted for conflict with 1.7.21) 
[INFO] | \- (org.slf4j:jcl-over-slf4j:jar:1.7.1:compile - scope updated from runtime; omitted for duplicate) 
[INFO] \- cglib:cglib:jar:2.2.2:compile 
[INFO] \- asm:asm:jar:3.3.1:compile 

UPDATE

私にとって、こののpom.xml作品:

<dependencies> 
    <!-- Spring framework --> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-core</artifactId> 
     <version>3.2.2.RELEASE</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-context</artifactId> 
     <version>3.2.2.RELEASE</version> 
    </dependency> 

    <!-- mongodb java driver --> 
    <dependency> 
     <groupId>org.mongodb</groupId> 
     <artifactId>mongo-java-driver</artifactId> 
     <version>2.10.1</version> 
    </dependency> 

    <!-- Spring data mongodb --> 
    <dependency> 
     <groupId>org.springframework.data</groupId> 
     <artifactId>spring-data-mongodb</artifactId> 
     <version>1.2.0.RELEASE</version> 

    </dependency> 

    <dependency> 
     <groupId>cglib</groupId> 
     <artifactId>cglib</artifactId> 
     <version>2.2.2</version> 
    </dependency> 

</dependencies> 

必ずきれいに作成し、プロジェクトをビルド。

+0

ありがとう....矛盾するすべての依存関係を削除しましたが、それでもエラーは継続します。 – anukuls

+0

あなたのプロジェクトをどのように実行しますか?それは 'jar'か' war'ですか?どのようにそれを構築しますか?あなたはそれを清潔な前に発行していますか? 'mvn cleanパッケージ'? 'hasProperty()'メソッドは 'MongoPersistentEntity'スーパークラスで利用できるはずです。依存関係のソースもダウンロードできれば、それを見ることができます。 – pleft

+0

jarを使って実行しますが、今すぐテストするには、mainメソッドを作成して実行しています。 – anukuls

関連する問題