Java Spring Boot MongoDB Configuration

Are you sure about your MongoDB URI? Usually, the URI has the form mongodb://localhost:27017/foo.

If you use Spring-boot instead of using a Configuration bean I suggest you use application.properties file. In this file write a property likes spring.data.mongodb.uri=mongodb://localhost:27017/foo and Spring-boot automatically injects the properties in MongoClient without any configuration at the code level.