You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This works well when main code also uses spring.data.mongodb.uri to connect to Mongo. It does not work when spring.data.mongodb.host etc have been used instead:
Caused by: java.lang.IllegalStateException: Invalid mongo configuration, either uri or host/port/credentials/replicaSet must be specified
at org.springframework.util.Assert.state(Assert.java:76) ~[spring-core-5.3.16.jar:5.3.16]
at org.springframework.boot.autoconfigure.mongo.MongoPropertiesClientSettingsBuilderCustomizer.validateConfiguration(MongoPropertiesClientSettingsBuilderCustomizer.java:61) ~[main/:na]
at org.springframework.boot.autoconfigure.mongo.MongoPropertiesClientSettingsBuilderCustomizer.customize(MongoPropertiesClientSettingsBuilderCustomizer.java:52) ~[main/:na]
at org.springframework.boot.autoconfigure.mongo.MongoClientFactorySupport.customize(MongoClientFactorySupport.java:55) ~[main/:na]
at org.springframework.boot.autoconfigure.mongo.MongoClientFactorySupport.createMongoClient(MongoClientFactorySupport.java:49) ~[main/:na]
at org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration.mongo(MongoAutoConfiguration.java:56) ~[main/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_252]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_252]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_252]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_252]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.16.jar:5.3.16]
... 196 common frames omitted
This can be worked around to some extent by overriding properties:
However, it does not work when the main configuration has set the username and password as an override cannot remove the configuration.
We need a more robust way of overriding the main configuration from a test. This will also be of benefit to Embedded Mongo where we currently only set local.mongo.port. It's possible with more advanced embedded Mongo configuration that other settings related to Mongo connectivity must also be set and we do not do so at the moment.
The text was updated successfully, but these errors were encountered:
wilkinsona
changed the title
Configuring spring.data.mongodb.uri from a test does not work when main configuration has set the host, port, credentials or replica set
Allow spring.data.mongodb.uri to take precedence over separate host, port, etc properties
Mar 23, 2022
wilkinsona
changed the title
Allow spring.data.mongodb.uri to take precedence over separate host, port, etc properties
Allow spring.data.mongodb.uri to override separate host, port, etc properties
Mar 23, 2022
When using Testcontainers, access to the Mongo instance in the container is available via a URL which is applied using a
@DynamicPropertySource
:This works well when main code also uses
spring.data.mongodb.uri
to connect to Mongo. It does not work whenspring.data.mongodb.host
etc have been used instead:This can be worked around to some extent by overriding properties:
However, it does not work when the main configuration has set the username and password as an override cannot remove the configuration.
We need a more robust way of overriding the main configuration from a test. This will also be of benefit to Embedded Mongo where we currently only set
local.mongo.port
. It's possible with more advanced embedded Mongo configuration that other settings related to Mongo connectivity must also be set and we do not do so at the moment.The text was updated successfully, but these errors were encountered: