@Configuration
@ConditionalOnClass([Jongo])
class JongoAutoConfiguration {
Logger log = Logger.getLogger(JongoAutoConfiguration)
@Autowired
protected Mongo mongo
DB rufusdb
@Autowired
protected MongoProperties properties
@Bean
DB rufusdb() {
this.rufusdb = mongo.getDB(properties.database)
return this.rufusdb
}
private Jongo getJongoDBObject() {
if (this.rufusdb == null) {
rufusdb()
}
if (rufusdb == null) {
log.error("rufudb is null")
} else {
log.error("rufudb is not null")
}
Mapper mapper = new JacksonMapper.Builder()
.registerModule(new JodaModule())
.enable(MapperFeature.AUTO_DETECT_GETTERS)
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.build()
return new Jongo(this.rufusdb, mapper)
}
@Bean
Jongo jongoConnection() {
getJongoDBObject()
}
@Bean
@DependsOn("rufusdb")
MongoCollection inventoryCollection() {
Jongo dbtmp = getJongoDBObject()
dbtmp.getCollection("inventory")
}
@Bean
@DependsOn("rufusdb")
MongoCollection configCollection() {
getJongoDBObject().getCollection("config")
}
}
and when i run it, i get this error:
Caused by: java.lang.NullPointerException: null
at com.mongodb.Mongo.createClientSession(Mongo.java:870) ~[mongo-java-driver-3.6.1.jar:na]
at com.mongodb.Mongo$3.getClientSession(Mongo.java:862) ~[mongo-java-driver-3.6.1.jar:na]
at com.mongodb.Mongo$3.execute(Mongo.java:819) ~[mongo-java-driver-3.6.1.jar:na]
at com.mongodb.Mongo$3.execute(Mongo.java:809) ~[mongo-java-driver-3.6.1.jar:na]
at com.mongodb.DBCursor.initializeCursor(DBCursor.java:870) ~[mongo-java-driver-3.6.1.jar:na]
at com.mongodb.DBCursor.hasNext(DBCursor.java:141) ~[mongo-java-driver-3.6.1.jar:na]
at com.mongodb.DBCursor.one(DBCursor.java:679) ~[mongo-java-driver-3.6.1.jar:na]
at com.mongodb.DBCollection.findOne(DBCollection.java:829) ~[mongo-java-driver-3.6.1.jar:na]
at com.mongodb.DBCollection.findOne(DBCollection.java:792) ~[mongo-java-driver-3.6.1.jar:na]
at com.mongodb.DBCollection.findOne(DBCollection.java:739) ~[mongo-java-driver-3.6.1.jar:na]
at com.mongodb.FongoDBCollection.createIndex(FongoDBCollection.java:522) ~[fongo-2.1.1.jar:na]
at com.mongodb.FongoDBCollection.<init>(FongoDBCollection.java:93) ~[fongo-2.1.1.jar:na]
at com.mongodb.FongoDB.doGetCollection(FongoDB.java:96) ~[fongo-2.1.1.jar:na]
at com.mongodb.FongoDB.doGetCollection(FongoDB.java:87) ~[fongo-2.1.1.jar:na]
at com.mongodb.FongoDB.getCollection(FongoDB.java:82) ~[fongo-2.1.1.jar:na]
at com.mongodb.FongoDB.getCollection(FongoDB.java:32) ~[fongo-2.1.1.jar:na]
at org.jongo.Jongo.getCollection(Jongo.java:42) ~[jongo-1.4.0.jar:na]
at org.jongo.Jongo$getCollection.call(Unknown Source) ~[na:na]
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) ~[groovy-all-2.4.12.jar:2.4.12]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) ~[groovy-all-2.4.12.jar:2.4.12]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) ~[groovy-all-2.4.12.jar:2.4.12]
at com.highmark.rufus.engine.JongoAutoConfiguration.inventoryCollection(JongoAutoConfiguration.groovy:70) ~[main/:na]
at com.highmark.rufus.engine.JongoAutoConfiguration$$EnhancerBySpringCGLIB$$86294ec4.CGLIB$inventoryCollection$5(<generated>) ~[main/:na]
at com.highmark.rufus.engine.JongoAutoConfiguration$$EnhancerBySpringCGLIB$$86294ec4$$FastClassBySpringCGLIB$$1588289d.invoke(<generated>) ~[main/:na]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:361) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at com.highmark.rufus.engine.JongoAutoConfiguration$$EnhancerBySpringCGLIB$$86294ec4.inventoryCollection(<generated>) ~[main/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
... 94 common frames omitted
I am trying to build unit tests for a spring boot app and its failing creating a session. Here's the code
and the applications jongo class is
and when i run it, i get this error: