title: Cannot resolve reference to bean 'mongoTemplate' while setting bean property 'mongoOperations
body: <p>I'm trying to create a spring boot CRUD App using MongoDB. But I'm unable to connect it to the MongoDB Atlas. When I'm running the program the below exception is shown. I'm trying to connect my application to MongDB Atlas clusters using the connection URL generated in the Mongo Atlas</p>
  <pre><code>org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'employeeController': Unsatisfied dependency expressed through field 'employeeRepo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employeeRepo' defined in com.example.mongo.repo.EmployeeRepo defined in @EnableMongoRepositories declared on MongoRepositoriesRegistrar.EnableMongoRepositoriesConfiguration: 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 java.lang.IllegalArgumentException: The connection string contains invalid user information. If the username or password contains a colon (:) or an at-sign (@) then it must be urlencoded
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643) ~[spring-beans-5.3.3.jar:5.3.3]
      at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119) ~[spring-beans-5.3.3.jar:5.3.3]
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) ~[spring-beans-5.3.3.jar:5.3.3]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1415) ~[spring-beans-5.3.3.jar:5.3.3]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:608) ~[spring-beans-5.3.3.jar:5.3.3]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:531) ~[spring-beans-5.3.3.jar:5.3.3]
      at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.3.jar:5.3.3]
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.3.jar:5.3.3]
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.3.jar:5.3.3]
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.3.jar:5.3.3]
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944) ~[spring-beans-5.3.3.jar:5.3.3]
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:923) ~[spring-context-5.3.3.jar:5.3.3]
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:588) ~[spring-context-5.3.3.jar:5.3.3]
      at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144) ~[spring-boot-2.4.2.jar:2.4.2]
      at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:767) ~[spring-boot-2.4.2.jar:2.4.2]
      at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) ~[spring-boot-2.4.2.jar:2.4.2]
      at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:426) ~[spring-boot-2.4.2.jar:2.4.2]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:326) ~[spring-boot-2.4.2.jar:2.4.2]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1311) ~[spring-boot-2.4.2.jar:2.4.2]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1300) ~[spring-boot-2.4.2.jar:2.4.2]
      at com.example.mongo.MongoApplication.main(MongoApplication.java:11) ~[classes/:an]
  </code></pre>
  <p>My Application class:</p>
  <pre><code>@SpringBootApplication
  public class MongoApplication {
  
      public static void main(String[] args) {
          SpringApplication.run(MongoApplication.class, args);
      }
  
  }
  </code></pre>
  <p>Controller class:</p>
  <pre><code>@RestController
  public class EmployeeController {
  
      @Autowired
      private EmployeeRepo employeeRepo;
  
      @Autowired
      private SequenceGeneratorService sequenceGeneratorService;
  
      @GetMapping(&quot;/employees&quot;)
      public List&lt;Employee&gt; getAllEmployees(){
          return employeeRepo.findAll();
      }
  
      @GetMapping(&quot;/employees/{id}&quot;)
      public Employee getEmployee(@PathVariable long id){
          Employee employee = employeeRepo.findById(id).get();
          return employee;
      }
  
      @PostMapping(&quot;/employees&quot;)
      public Employee addEmployee(@RequestBody Employee employee){
          employee.setId(sequenceGeneratorService.generateSequence(Employee.SEQUENCE_NAME));
          return employeeRepo.save(employee);
      }
  }
  </code></pre>
  <p>Repository:</p>
  <pre><code>public interface EmployeeRepo extends MongoRepository&lt;Employee, Long&gt; {
  }
  </code></pre>
  <p>Model class:</p>
  <pre><code>@Document(collation = &quot;Employee&quot;)                                                                            
  public class Employee {                                                                                      
                                                                                                               
      @Transient                                                                                               
      public static final String SEQUENCE_NAME = &quot;users_sequence&quot;;                                             
                                                                                                               
      @Id                                                                                                      
      private long id;                                                                                         
                                                                                                               
      @Indexed(unique = true)                                                                                  
      private String firstName;                                                                                
      private String lastName;                                                                                 
                                                                                                               
      @Indexed(unique = true)                                                                                  
      private String email;                                                                                    
                                                                                                               
      public Employee() {                                                                                      
      }                                                                                                        
                                                                                                               
      public Employee(long id, String firstName, String lastName, String email) {                              
          this.id = id;                                                                                        
          this.firstName = firstName;                                                                          
          this.lastName = lastName;                                                                            
          this.email = email;                                                                                  
      }                                                                                                        
                                                                                                               
      public Employee(String firstName, String lastName, String email) {                                       
          this.firstName = firstName;                                                                          
          this.lastName = lastName;                                                                            
          this.email = email;                                                                                  
      }                                                                                                        
              
      /** Getters and setters **/
      
  }
  </code></pre>
  <p>Application Properties:</p>
  <pre><code>spring.data.mongodb.uri=mongodb+srv://root:Luxan@22@testcluster.4ebwy.mongodb.net/EmployeeDB?retryWrites=true&amp;w=majority
                                                                                               
  </code></pre>