[JAVA-2340] Moving apps to Mongo 3.2.2 driver and getting error Created: 10/Oct/16  Updated: 11/Sep/19  Resolved: 10/Oct/16

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: 3.2.2
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: pradeep Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

spring boot



 Description   

In my app I am trying to use mongo java 3.2.2 driver and seeing below errors.
I made sure that there is no libraries duplication or old libraries.

TRACKING_ID:null ACCOUNT_NUM:null SESSION_ID:null] com.comcast.MongoDBConfiguration.mongoTemplate - Error occurred when creating the mongoTemplate.......ERROR_MESSAGE: Error creating bean with name 'mongoDbFactory' defined in class path resource [com/comcast/sparrow/activatorweb/repository/MongoDBConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.MongoDbFactory]: Factory method 'mongoDbFactory' threw exception;

nested exception is java.lang.IllegalAccessError: tried to access method org.bson.types.ObjectId.<init>(III)V from class com.mongodb.Bytes

ERROR_DETAILS: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoDbFactory' defined in class path resource [com/comcast/sparrow/activatorweb/repository/MongoDBConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.MongoDbFactory]: Factory method 'mongoDbFactory' threw exception; nested exception is java.lang.IllegalAccessError: tried to access method org.bson.types.ObjectId.<init>(III)V from class com.mongodb.Bytes at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1128) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1023) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:381) at com.comcast.sparrow.activatorweb.repository.MongoDBConfiguration$$EnhancerBySpringCGLIB$$bd6b329d.mongoDbFactory(<generated>) at com.comcast.sparrow.activatorweb.repository.MongoDBConfiguration.mongoTemplate(MongoDBConfiguration.java:68) at com.comcast.sparrow.activatorweb.repository.MongoDBConfiguration$$EnhancerBySpringCGLIB$$bd6b329d.CGLIB$mongoTemplate$0(<generated>) at com.comcast.sparrow.activatorweb.repository.MongoDBConfiguration$$EnhancerBySpringCGLIB$$bd6b329d$$FastClassBySpringCGLIB$$ecc75b5b.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356) at com.comcast.sparrow.activatorweb.repository.MongoDBConfiguration$$EnhancerBySpringCGLIB$$bd6b329d.mongoTemplate(<generated>) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) at org.springframework



 Comments   
Comment by Jeffrey Yemin [ 10/Oct/16 ]

The relevant part of the error message is:

tried to access method org.bson.types.ObjectId.<init>(III)V from class com.mongodb.Bytes

The version of the Bytes class in the 3.x driver does not call any ObjectId constructors, while the version in the 2.x driver does.

So it does appear that you have an old version of the mongo-java-driver on your classpath. I suggest that you start your application with -verbose:class specified on the java command line. That will tell you where the Bytes class is being loaded from.

Generated at Thu Feb 08 08:56:58 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.