Dave Dave -4 years ago 232
Java Question

Usage of UserCredentials with MongoClient is no longer supported

I am trying to deploy my spring boot app to cloud foundry. However I am receiving the below error.

2016-02-19T16:54:29.57+0000 [App/0] ERR Caused by: org.springframework.dao.InvalidDataAccessApiUsageException: Usage of 'UserCredentials' with 'MongoClient' is no longer supported. Please use 'MongoCredential' for 'MongoClient' or just 'Mongo'.
2016-02-19T16:54:29.57+0000 [App/0] ERR at org.springframework.data.mongodb.core.SimpleMongoDbFactory.<init>(SimpleMongoDbFactory.java:137)
2016-02-19T16:54:29.57+0000 [App/0] ERR at org.springframework.data.mongodb.core.SimpleMongoDbFactory.<init>(SimpleMongoDbFactory.java:78)
2016-02-19T16:54:29.57+0000 [App/0] ERR at org.cloudfoundry.reconfiguration.org.springframework.cloud.service.document.MongoDbFactoryCreator.create(MongoDbFactoryCreator.java:46)
2016-02-19T16:54:29.57+0000 [App/0] ERR at org.cloudfoundry.reconfiguration.org.springframework.cloud.service.document.MongoDbFactoryCreator.create(MongoDbFactoryCreator.java:35)
2016-02-19T16:54:29.57+0000 [App/0] ERR at org.cloudfoundry.reconfiguration.org.springframework.cloud.Cloud.getServiceConnector(Cloud.java:257)
2016-02-19T16:54:29.57+0000 [App/0] ERR at org.cloudfoundry.reconfiguration.org.springframework.cloud.Cloud.getSingletonServiceConnector(Cloud.java:167)
2016-02-19T16:54:29.57+0000 [App/0] ERR at org.cloudfoundry.reconfiguration.spring.AbstractCloudServiceBeanFactoryPostProcessor.reconfigureBean(AbstractCloudServiceBeanFactoryPostProcessor.java:119)

It was my understanding the Spring Boot will automatically find the bound Mongo service and all the necessary user credentials and URI details, meaning I don't need to explicitly declare these variables.

Does anyone know why I am receiving this error and how I can solve it?

Here is my Java code snippet:

public MongoRepository(MongoClient mongo) {
this.mongo = mongo;

public long insert(Document document){

MongoDatabase db = mongo.getDatabase("test");
MongoCollection<Document> coll = db.getCollection("document");

I am using Mongo3.0 java driver.


Answer Source

You are relying on Cloud Foundry Java buildpack auto-configuration to configure the MongoDB connection. The Java buildpack depends on Spring Cloud Connectors, Spring Data MongoDB, and the MongDB client library to create the necessary connection beans. The MongoDB client made some changes a while ago that required Spring Data MongDB and Spring Cloud Connectors to make changes also. It appears that the Java Buildpack you are using depends on older versions of these libraries.

You have a few options.

You could use a newer version of the Java buildpack to push your app. It appears that version 3.2 and later of JBP have the correct libraries for your needs.

Alternatively, you could explicitly include Spring Cloud Connectors version 1.2.0 or later in your application, which effectively disables Java buildpack auto-configuration. See the Connectors docs for more info on this approach.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download