AbstractReactiveMongoConfiguration seems related to spring boot trying mongodb at 127.0.0.1
See original GitHub issueI am testing a webflux application with spring-boot-starter-data-mongodb-reactive, and used AbstractReactiveMongoConfiguration to setup custom mongodb converters as explained in https://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#mongo.custom-converters.xml.
Using docker, I get monitor exceptions and connection errors:
First attempt:
demo_1 | 2021-10-27 06:09:07.032 INFO 1 --- [ main] org.mongodb.driver.cluster : Cluster created with settings {hosts=[127.0.0.1:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms'}
demo_1 | 2021-10-27 06:09:07.098 INFO 1 --- [127.0.0.1:27017] org.mongodb.driver.cluster : Exception in monitor thread while connecting to server 127.0.0.1:27017
Second attempt with the right configuration:
demo_1 | 2021-10-27 06:09:09.952 INFO 1 --- [ main] org.mongodb.driver.cluster : Cluster created with settings {hosts=[mongodb:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms'}
Failed query request:
demo_1 | 2021-10-27 06:11:57.982 INFO 1 --- [or-http-epoll-2] org.mongodb.driver.cluster : No server chosen by com.mongodb.reactivestreams.client.internal.ClientSessionHelper$$Lambda$1458/0x000000080130dc30@63c1fe3e from cluster description ClusterDescription{type=UNKNOWN, connectionMode=SINGLE, serverDescriptions=[ServerDescription{address=127.0.0.1:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused}}]}. Waiting for 30000 ms before timing out
If I remove the AbstractReactiveMongoConfiguration, and configured converters with:
@Bean
public MongoCustomConversions mongoCustomConversions() {
return new MongoCustomConversions(
Arrays.asList(...);
}
The spring-boot app no longer tries 127.0.0.1. Is it the wrong choice to use AbstractReactiveMongoConfiguration with spring-boot-starter-data-mongodb-reactive?
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (1 by maintainers)
Using
AbstractReactiveMongoConfiguration
defines MongoDB infrastructure beans that let Spring Boot back off from bean creation and therefore, Spring Boot properties are no longer applicable. If you want to defineMongoCustomConversions
within a Spring Boot application, then just define the custom conversions bean without subclassingAbstractReactiveMongoConfiguration
.I am facing the same issue here. @Bean public MongoClient mongoClient() { ConnectionString connectionString = new ConnectionString(“”); MongoClientSettings mongoClientSettings = MongoClientSettings.builder() .applyConnectionString(connectionString) .build(); return MongoClients.create(mongoClientSettings); }