I'm getting "Invalid mongo configuration, either uri or host/port/credentials/replicaSet must be specified" even configuring the uri.
This error happens on following versions that I've tested: 2.3.3.RELEASE 2.3.4.RELEASE 2.3.4.RELEASE
There is my uri configuration below, the same works on 2.2.6.RELEASE (by example) perfectly:
spring:
data:
mongodb:
uri: mongodb://${MONGODB_USER}:${MONGODB_REPLICA_PASSWORD}@${MONGODB_HOSTS}/${MONGODB_DATABASE}?replicaSet=${MONGODB_REPLICA_SET}&connectTimeoutMS=${timeoutMS}&socketTimeoutMS=${TIMEOUT_MS}&maxPoolSize=${MAX_POOL_SIZE}&maxIdleTimeMS=${MAX_IDLE_TIME_MS}
Here are the error logs:
o.s.b.web.embedded.tomcat.TomcatStarter : Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'tracingFilter' defined in class path resource [org/springframework/cloud/sleuth/instrument/web/TraceWebServletAutoConfiguration.class]: Unsatisfied dependency expressed through method 'tracingFilter' parameter 0;
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'httpTracing' defined in class path resource [org/springframework/cloud/sleuth/instrument/web/TraceHttpAutoConfiguration.class]: Unsatisfied dependency expressed through method 'httpTracing' parameter 1;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sleuthSkipPatternProvider' defined in class path resource [org/springframework/cloud/sleuth/instrument/web/TraceWebAutoConfiguration.class]: Bean instantiation via factory method failed;
nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.sleuth.instrument.web.SkipPatternProvider]: Factory method 'sleuthSkipPatternProvider' threw exception;
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Unsatisfied dependency expressed through method 'healthEndpoint' parameter 0;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthContributorRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Bean instantiation via factory method failed;
nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthContributorRegistry]: Factory method 'healthContributorRegistry' threw exception;
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mongoHealthContributor' defined in class path resource [org/springframework/boot/actuate/autoconfigure/mongo/MongoHealthContributorAutoConfiguration.class]: Unsatisfied dependency expressed through method 'mongoHealthContributor' parameter 0;
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mongoTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDatabaseFactoryDependentConfiguration.class]: Unsatisfied dependency expressed through method 'mongoTemplate' parameter 0;
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mongoDatabaseFactory' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDatabaseFactoryConfiguration.class]: Unsatisfied dependency expressed through method 'mongoDatabaseFactory' parameter 0;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongo' defined in class path resource [org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration.class]: Bean instantiation via factory method failed;
nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.mongodb.client.MongoClient]: Factory method 'mongo' threw exception;
nested exception is java.lang.IllegalStateException: Invalid mongo configuration, either uri or host/port/credentials/replicaSet must be specified
Comment From: wilkinsona
That failure occurs when you have set spring.data.mongodb.uri
and one or more of the following
spring.data.mongodb.host
spring.data.mongodb.port
spring.data.mongodb.username
spring.data.mongodb.password
spring.data.mongodb.replica-set-name
If your application works with 2.2.x and fails with 2.3.x, replica-set-name
is the most likely candidate due to this enhancement.
I'd recommend checking your other application properties, system properties and environment variables to identify the problematic property. If you're using spring.data.mongodb.uri
to configure Mongo, the other properties can perhaps just be removed.
If the above doesn't help and you are certain you're not setting any of the five properties listed above, please provide a complete yet minimal sample that works with 2.2.x and fails with 2.3.x and we can re-open this issue and take another look.