Hello,
I followed some tutorials to learn how to make MongoDB work with Spring and everything was really easy locally.
Today, I decided to deploy my database to MongoDB Atlas and I’m struggling for few hours without understanding what is happening.
Before, I had this application.properties :
spring.data.mongodb.authentication-database=admin
spring.data.mongodb.username=rootuser
spring.data.mongodb.password=rootpass
spring.data.mongodb.database=dz-database
spring.data.mongodb.port=27017
spring.data.mongodb.host=localhost
spring.data.mongodb.auto-index-creation=true
server.error.include-message=always
After, I had this one :
spring.data.mongodb.uri=mongodb+srv://redouane59:<**my_password**>@dz-cluster.ijmc9sx.mongodb.net/?retryWrites=true&w=majority
I took it from the MongoDB Atlas page after clicking to the “connect” button.
When I want to start my Application, here is the exception I get after a few seconds :
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'pronounService' defined in file [C:\Users\Perso\Documents\GitHub\dz-dialect-api-spring\target\classes\io\github\dzdialectapispring\pronoun\PronounService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pronounRepository' defined in io.github.dzdialectapispring.pronoun.PronounRepository defined in @EnableMongoRepositories declared on PronounService: Cannot resolve reference to bean 'mongoTemplate' while setting bean property 'mongoOperations'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mongoTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDatabaseFactoryDependentConfiguration.class]: Unsatisfied dependency expressed through method 'mongoTemplate' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mongoDatabaseFactory' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDatabaseFactoryConfiguration.class]: Unsatisfied dependency expressed through method 'mongoDatabaseFactory' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongo' defined in class path resource [org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.mongodb.client.MongoClient]: Factory method 'mongo' threw exception; nested exception is com.mongodb.MongoConfigurationException: Failed looking up TXT record for host dz-cluster.ijmc9sx.mongodb.net
It’s really not clear for me and I’m really lost.
Any idea ?
Full GitHub repository is available here : GitHub - redouane59/dz-dialect-api-spring: spring fork of dz dialect api project (only application.properties file is not up to date).
Thanks !