连接到服务器本地主机时,在监视器线程中连接远程MongoDB异常时出错:27017



我正在尝试连接到远程地图集库,但是看起来我被重定向到本地主机。我像往常一样配置了spring.data.mongodb.uri,几天前同一个项目正在工作,其他具有相同结构的项目正在正常工作。使用相同的连接 uri,我可以通过 mongoDB 客户端进行连接。 我使用的是 Spring boot 2.6,下面是通过 gradle 使用的依赖项

compile group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
compile group: 'net.sourceforge.htmlunit', name: 'htmlunit', version: '2.39.1'
compile group: 'org.apache.pdfbox', name: 'pdfbox', version: '2.0.17'
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-openfeign', version: '2.1.3.RELEASE'
compile group: 'io.github.openfeign.form', name: 'feign-form', version: '3.8.0'
compile group: 'io.github.openfeign', name: 'feign-jaxb', version: '10.7.4'
compile ('io.springfox:springfox-swagger2:2.8.0')
compile ('io.springfox:springfox-swagger-ui:2.8.0')
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.0'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.3.1'
compile group: 'com.github.mpkorstanje', name: 'simmetrics-core', version: '4.1.1'
compile group: 'org.apache.poi', name: 'poi', version: '4.1.1'
compile group: 'org.apache.poi', name: 'poi-ooxml', version: '4.1.1'
compile group: 'org.apache.poi', name: 'poi-scratchpad', version: '4.1.1'
compile group: 'org.apache.tika', name: 'tika-parsers', version: '1.23'
compile group: 'org.apache.tika', name: 'tika-core', version: '1.23'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
testCompile group: 'com.google.caliper', name: 'caliper', version: '0.5-rc1'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}```
This log error: "Exception in monitor thread while connecting to server localhost:27017"
I saw some comments telling me to disable @EnableAutoConfiguration (exclude = {MongoAutoConfiguration.class}), however, it didn't work, after all I'm trying to connect to a remote mongo and don't disable it.
It seems to me something related to the configuration of routes / dns something like that, I don't know, I'm confused about that. Would any good soul know how to help me?

使用自动配置"ON",它使用指向 localhost:27017 的默认值。这就是为什么你看到评论告诉排除MongoAutoConfiguration和MongoDataAutoConfiguration在SpringBootApplication/EnableAutoConfiguration注释中。

我建议您以编程方式(而不是自动(配置 mongodb 并覆盖这些 props。

spring.data.mongodb.host=mongoserver.example.com
spring.data.mongodb.port=27017
spring.data.mongodb.database=test
spring.data.mongodb.username=user
spring.data.mongodb.password=secret

最新更新