mongodb中的错误:java.lang.NoSuchFieldError:INSTANCE

时间:2017-01-04 16:58:35

标签: java mongodb hibernate maven spring-mvc

我正在使用maven来管理jar,我对mongodb的依赖关系如下:

<!-- https://mvnrepository.com/artifact/org.mongodb/mongo-java-driver -->
    <dependency>
        <groupId>org.mongodb</groupId>
        <artifactId>mongo-java-driver</artifactId>
        <version>3.4.1</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-mongodb -->
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-mongodb</artifactId>
        <version>1.9.5.RELEASE</version>
    </dependency>

但是当我启动springmvc程序时,出现错误:

Caused by: java.lang.NoSuchFieldError: INSTANCE
at org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper.<init>(DefaultMongoTypeMapper.java:65)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.<init>(MappingMongoConverter.java:108)
at org.springframework.data.mongodb.config.AbstractMongoConfiguration.mappingMongoConverter(AbstractMongoConfiguration.java:192)
at com.aixueniao.server.configuration.MongoConfig$$EnhancerBySpringCGLIB$$ee562bf3.CGLIB$mappingMongoConverter$5(<generated>)
at com.aixueniao.server.configuration.MongoConfig$$EnhancerBySpringCGLIB$$ee562bf3$$FastClassBySpringCGLIB$$973f1472.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:312)
at com.aixueniao.server.configuration.MongoConfig$$EnhancerBySpringCGLIB$$ee562bf3.mappingMongoConverter(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:166)
... 85 more

有人可以告诉我它有什么问题吗?也许依赖项的版本存在错误,但我该如何解决?提前谢谢。

1 个答案:

答案 0 :(得分:0)

它是一个多库版本冲突error.simple方法会降低你的spring-data-mongodb版本1.9.5.RELEASE到1.7.2.RELEASE

 <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-mongodb</artifactId>
        <version>1.7.2.RELEASE</version>
  </dependency>

否则尝试查找冲突库并在spring-data-mongodb dependancy中应用排除