question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AbstractReactiveMongoConfiguration seems related to spring boot trying mongodb at 127.0.0.1

See original GitHub issue

I 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:closed
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
mp911decommented, Oct 27, 2021

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 define MongoCustomConversions within a Spring Boot application, then just define the custom conversions bean without subclassing AbstractReactiveMongoConfiguration.

0reactions
quanghuonggcommented, Mar 7, 2022

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); }

Read more comments on GitHub >

github_iconTop Results From Across the Web

Springboot ignores the MongoDB atlas uri, trying to connect ...
HoOwever now i no longer can connect to mongo db atlas, it ignores the proeprty spring.data.mongodb.uri and tries to connect local server with ......
Read more >
How to connect to mongodb on remote server from spring boot?
I have a Spring boot application configured wih MongoDB.Everything worked just fine when working with mongodb on localhost.
Read more >
Spring Data MongoDB - Reference Documentation
The Spring Data MongoDB project applies core Spring concepts to the development of solutions that use the MongoDB document style data store.
Read more >
Spring Data Reactive Repositories with MongoDB - Baeldung
But, as we're using Spring Boot with embedded MongoDB in our example, the above configuration is not necessary. 4. Creating a Document.
Read more >
Java Driver - automatic connection localhost:27017
Integrated with Spring Boot - automatic connection localhost:27017 ... INFO org.mongodb.driver.cluster -Exception in monitor thread while ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found