Mongo tries to connect automatically to port 27017(localhost)

后端 未结 4 1594
小鲜肉
小鲜肉 2020-12-05 23:14

I am using Spring Rest and Mongo in Maven to make a web service that connects to a server. The problem is that I haven\'t written any code for Mongo and it is trying to conn

相关标签:
4条回答
  • 2020-12-05 23:49

    Spring Boot has a feature called "auto configuration". In this case, as soon as the Mongo driver is detected on the classpath, the MongoAutoConfiguration is activated with default values, which point to localhost:27017. If you don't want that behaviour, you can now either configure the properties for MongoDB (see http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-mongodb for valid property keys) or disable the MongoAutoConfiguration:

    @SpringBootApplication(exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class})
    
    0 讨论(0)
  • 2020-12-05 23:53

    Spring boot throws this exception when Mongo DB is not running. Please make sure that Mongodb is running. It got resolved for me after starting Mongo DB.

    0 讨论(0)
  • 2020-12-05 23:54

    for springboot, you should add following config to your application.property

    spring.data.mongodb.host=localhost(your mongo server)
    spring.data.mongodb.port=27017(mongo port)
    
    0 讨论(0)
  • 2020-12-05 23:57

    In some cases, if you are using reactive you also need to remove MongoReactiveAutoConfiguration

    spring:
      autoconfigure:
        exclude:
          - org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration
          - org.springframework.boot.autoconfigure.mongo.MongoReactiveAutoConfiguration
    
    0 讨论(0)
提交回复
热议问题