Not able to run mflix project

Hi Everyone,

I am getting below error while running mflix project.

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.mongodb.client.MongoClient]: Factory method ‘mongoClient’ threw exception; nested exception is com.mongodb.MongoConfigurationException: Unable to look up SRV record for host mflix-6j2xv.mongodb.net
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:582) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
… 58 common frames omitted
Caused by: com.mongodb.MongoConfigurationException: Unable to look up SRV record for host mflix-6j2xv.mongodb.net
at com.mongodb.internal.dns.DnsResolver.resolveHostFromSrvRecords(DnsResolver.java:79) ~[mongodb-driver-core-3.9.1.jar:na]
at com.mongodb.ConnectionString.(ConnectionString.java:325) ~[mongodb-driver-core-3.9.1.jar:na]
at mflix.config.MongoDBConfiguration.mongoClient(MongoDBConfiguration.java:25) ~[classes/:na]
at mflix.config.MongoDBConfiguration$$EnhancerBySpringCGLIB$$ef5048a.CGLIB$mongoClient$0() ~[classes/:na]
at mflix.config.MongoDBConfiguration$$EnhancerBySpringCGLIB$$ef5048a$$FastClassBySpringCGLIB$$f5ca69ec.invoke() ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:361) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at mflix.config.MongoDBConfiguration$$EnhancerBySpringCGLIB$$ef5048a.mongoClient() ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_181]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_181]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_181]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
… 59 common frames omitted
Caused by: javax.naming.CommunicationException: DNS error
at com.sun.jndi.dns.DnsClient.query(Unknown Source) ~[na:1.8.0_181]
at com.sun.jndi.dns.Resolver.query(Unknown Source) ~[na:1.8.0_181]
at com.sun.jndi.dns.DnsContext.c_getAttributes(Unknown Source) ~[na:1.8.0_181]
at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_getAttributes(Unknown Source) ~[na:1.8.0_181]
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(Unknown Source) ~[na:1.8.0_181]
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(Unknown Source) ~[na:1.8.0_181]
at javax.naming.directory.InitialDirContext.getAttributes(Unknown Source) ~[na:1.8.0_181]
at com.mongodb.internal.dns.DnsResolver.resolveHostFromSrvRecords(DnsResolver.java:60) ~[mongodb-driver-core-3.9.1.jar:na]
… 71 common frames omitted
Caused by: java.net.SocketTimeoutException: Receive timed out
at java.net.DualStackPlainDatagramSocketImpl.socketReceiveOrPeekData(Native Method) ~[na:1.8.0_181]
at java.net.DualStackPlainDatagramSocketImpl.receive0(Unknown Source) ~[na:1.8.0_181]
at java.net.AbstractPlainDatagramSocketImpl.receive(Unknown Source) ~[na:1.8.0_181]
at java.net.DatagramSocket.receive(Unknown Source) ~[na:1.8.0_181]
at com.sun.jndi.dns.DnsClient.doUdpQuery(Unknown Source) ~[na:1.8.0_181]
… 79 common frames omitted

Firewall, VPN or internet provider not supporting SRV DNS.

Hi @Amitabh_Jaiswal,

Please let me know if you are still facing issues.

Kanika

Hello I have the same issue. I can connect to my cluster using a mongo cli but whrn it comes to the application Mflix I also have the "Unable to look up SRV record for host ‘’. I’m on Win 10 and I tried also to reset the firewall configurations… can u help me please? Thanks

A screenshot of the error.

   020-05-03 18:24:12.519  INFO 8648 --- [           main] mflix.Application                        : Starting Application on DESKTOP-F4PT7SF with PID 8648 (C:\Users\Fab\Downloads\mflix\target\classes started by Fab in C:\Users\Fab\Downloads\mflix)
2020-05-03 18:24:12.553  INFO 8648 --- [           main] mflix.Application                        : No active profile set, falling back to default profiles: default
2020-05-03 18:24:12.680  INFO 8648 --- [           main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@7d3a22a9: startup date [Sun May 03 18:24:12 CEST 2020]; root of context hierarchy
2020-05-03 18:24:14.789  INFO 8648 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 5000 (http)
2020-05-03 18:24:14.811  INFO 8648 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-05-03 18:24:14.811  INFO 8648 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.31
2020-05-03 18:24:14.817  INFO 8648 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jdk1.8.0_251\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\Java\jdk1.8.0_251\bin;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\nodejs\;C:\apache-maven-3.6.3\bin;C:\Program Files\Git\cmd;C:\Users\Fab\Downloads\apache-maven-3.6.3-bin\apache-maven-3.6.3\bin;C:\Program Files\gradle-6.3\bin;C:\Program Files\MongoDB\Server\4.2\bin;C:\Program Files\Zulu\zulu-8\bin\;C:\Users\Fab\AppData\Local\Microsoft\WindowsApps;;.]
2020-05-03 18:24:15.594  INFO 8648 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2020-05-03 18:24:15.594  INFO 8648 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2914 ms
2020-05-03 18:24:15.782  INFO 8648 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2020-05-03 18:24:15.783  INFO 8648 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2020-05-03 18:24:15.783  INFO 8648 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2020-05-03 18:24:15.783  INFO 8648 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2020-05-03 18:24:15.783  INFO 8648 --- [ost-startStop-1] .s.DelegatingFilterProxyRegistrationBean : Mapping filter: 'springSecurityFilterChain' to: [/*]
2020-05-03 18:24:15.784  INFO 8648 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
2020-05-03 18:24:30.955  WARN 8648 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'movieController': Unsatisfied dependency expressed through field 'moviesService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'moviesService': Unsatisfied dependency expressed through field 'movieDao'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'movieDao' defined in file [C:\Users\Fab\Downloads\mflix\target\classes\mflix\api\daos\MovieDao.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoClient' defined in class path resource [mflix/config/MongoDBConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.mongodb.client.MongoClient]: Factory method 'mongoClient' threw exception; nested exception is com.mongodb.MongoConfigurationException: Unable to look up SRV record for host mflix-esgqq.mongodb.net
2020-05-03 18:24:30.958  INFO 8648 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2020-05-03 18:24:30.972  INFO 8648 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-05-03 18:24:30.983 ERROR 8648 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'movieController': Unsatisfied dependency expressed through field 'moviesService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'moviesService': Unsatisfied dependency expressed through field 'movieDao'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'movieDao' defined in file [C:\Users\Fab\Downloads\mflix\target\classes\mflix\api\daos\MovieDao.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoClient' defined in class path resource [mflix/config/MongoDBConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.mongodb.client.MongoClient]: Factory method 'mongoClient' threw exception; nested exception is com.mongodb.MongoConfigurationException: Unable to look up SRV record for host mflix-esgqq.mongodb.net
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:587) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:373) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1350) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:580) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:503) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:760) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:398) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:330) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1258) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
	at mflix.Application.main(Application.java:10) [classes/:na]
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'moviesService': Unsatisfied dependency expressed through field 'movieDao'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'movieDao' defined in file [C:\Users\Fab\Downloads\mflix\target\classes\mflix\api\daos\MovieDao.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoClient' defined in class path resource [mflix/config/MongoDBConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.mongodb.client.MongoClient]: Factory method 'mongoClient' threw exception; nested exception is com.mongodb.MongoConfigurationException: Unable to look up SRV record for host mflix-esgqq.mongodb.net
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:587) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:373) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1350) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:580) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:503) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:584) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	... 19 common frames omitted
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'movieDao' defined in file [C:\Users\Fab\Downloads\mflix\target\classes\mflix\api\daos\MovieDao.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoClient' defined in class path resource [mflix/config/MongoDBConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.mongodb.client.MongoClient]: Factory method 'mongoClient' threw exception; nested exception is com.mongodb.MongoConfigurationException: Unable to look up SRV record for host mflix-esgqq.mongodb.net
	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:732) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:197) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1276) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1133) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:503) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:584) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	... 32 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoClient' defined in class path resource [mflix/config/MongoDBConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.mongodb.client.MongoClient]: Factory method 'mongoClient' threw exception; nested exception is com.mongodb.MongoConfigurationException: Unable to look up SRV record for host mflix-esgqq.mongodb.net
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:590) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1256) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1105) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:503) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:818) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:724) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	... 45 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.mongodb.client.MongoClient]: Factory method 'mongoClient' threw exception; nested exception is com.mongodb.MongoConfigurationException: Unable to look up SRV record for host mflix-esgqq.mongodb.net
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:582) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	... 58 common frames omitted
Caused by: com.mongodb.MongoConfigurationException: Unable to look up SRV record for host mflix-esgqq.mongodb.net
	at com.mongodb.internal.dns.DnsResolver.resolveHostFromSrvRecords(DnsResolver.java:79) ~[mongodb-driver-core-3.9.1.jar:na]
	at com.mongodb.ConnectionString.<init>(ConnectionString.java:325) ~[mongodb-driver-core-3.9.1.jar:na]
	at mflix.config.MongoDBConfiguration.mongoClient(MongoDBConfiguration.java:25) ~[classes/:na]
	at mflix.config.MongoDBConfiguration$$EnhancerBySpringCGLIB$$84df6ba0.CGLIB$mongoClient$0(<generated>) ~[classes/:na]
	at mflix.config.MongoDBConfiguration$$EnhancerBySpringCGLIB$$84df6ba0$$FastClassBySpringCGLIB$$7f249eae.invoke(<generated>) ~[classes/:na]
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:361) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at mflix.config.MongoDBConfiguration$$EnhancerBySpringCGLIB$$84df6ba0.mongoClient(<generated>) ~[classes/:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_251]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_251]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_251]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_251]
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	... 59 common frames omitted
Caused by: javax.naming.CommunicationException: DNS error
	at com.sun.jndi.dns.DnsClient.query(DnsClient.java:312) ~[na:1.8.0_251]
	at com.sun.jndi.dns.Resolver.query(Resolver.java:81) ~[na:1.8.0_251]
	at com.sun.jndi.dns.DnsContext.c_getAttributes(DnsContext.java:434) ~[na:1.8.0_251]
	at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_getAttributes(ComponentDirContext.java:235) ~[na:1.8.0_251]
	at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:141) ~[na:1.8.0_251]
	at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:129) ~[na:1.8.0_251]
	at javax.naming.directory.InitialDirContext.getAttributes(InitialDirContext.java:142) ~[na:1.8.0_251]
	at com.mongodb.internal.dns.DnsResolver.resolveHostFromSrvRecords(DnsResolver.java:60) ~[mongodb-driver-core-3.9.1.jar:na]
	... 71 common frames omitted
Caused by: java.net.SocketTimeoutException: Receive timed out
	at java.net.DualStackPlainDatagramSocketImpl.socketReceiveOrPeekData(Native Method) ~[na:1.8.0_251]
	at java.net.DualStackPlainDatagramSocketImpl.receive0(DualStackPlainDatagramSocketImpl.java:124) ~[na:1.8.0_251]
	at java.net.AbstractPlainDatagramSocketImpl.receive(AbstractPlainDatagramSocketImpl.java:143) ~[na:1.8.0_251]
	at java.net.DatagramSocket.receive(DatagramSocket.java:812) ~[na:1.8.0_251]
	at com.sun.jndi.dns.DnsClient.doUdpQuery(DnsClient.java:422) ~[na:1.8.0_251]
	at com.sun.jndi.dns.DnsClient.query(DnsClient.java:211) ~[na:1.8.0_251]
	... 78 common frames omitted


Process finished with exit code 1

I tried an AZUL JDK8 and now I switched to an Oracle JDK8, same result. I also tried to bump the version of the mongodb-sync-driver but same result.

$ mongo "mongodb+srv://mflix-esgqq.mongodb.net/test"  --username m220student --password xxxxxxx
MongoDB shell version v4.2.6
connecting to: mongodb://mflix-shard-00-00-esgqq.mongodb.net:27017,mflix-shard-00-01-esgqq.mongodb.net:27017,mflix-shard-00-02-esgqq.mongodb.net:27017/test?authSource=admin&compressors=disabled&gssapiServiceName=mongodb&replicaSet=mflix-shard-0&ssl=true
2020-05-03T18:22:43.220+0200 I  NETWORK  [js] Starting new replica set monitor for mflix-shard-0/mflix-shard-00-00-esgqq.mongodb.net:27017,mflix-shard-00-01-esgqq.mongodb.net:27017,mflix-shard-00-02-esgqq.mongodb.net:27017
2020-05-03T18:22:43.220+0200 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to mflix-shard-00-00-esgqq.mongodb.net:27017
2020-05-03T18:22:43.220+0200 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to mflix-shard-00-02-esgqq.mongodb.net:27017
2020-05-03T18:22:43.220+0200 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to mflix-shard-00-01-esgqq.mongodb.net:27017
2020-05-03T18:22:43.904+0200 I  NETWORK  [ReplicaSetMonitor-TaskExecutor] Confirmed replica set for mflix-shard-0 is mflix-shard-0/mflix-shard-00-00-esgqq.mongodb.net:27017,mflix-shard-00-01-esgqq.mongodb.net:27017,mflix-shard-00-02-esgqq.mongodb.net:27017
Implicit session: session { "id" : UUID("7e3a8542-b34c-4394-8ea3-fb847f3b7114") }
MongoDB server version: 4.2.6
show dbs
admin               0.000GB
local               3.930GB
sample_airbnb       0.051GB
sample_analytics    0.009GB
sample_geospatial   0.001GB
sample_mflix        0.040GB
sample_supplies     0.001GB
sample_training     0.059GB
sample_weatherdata  0.002GB

By trying with mongo, you already answered my next question. Because I could see that the DNS entries were fine.

May be there is some spaces at the wrong place in your application.properties. Could you please share it?

spring.mongodb.uri=mongodb+srv://m220student:xxxxxxx@mflix-esgqq.mongodb.net/test?retryWrites=true&w=majority

Is /test… on the same line as the rest?

of course just the forum put it like this…

May be the course has changed but are the user name and password correct? In my time it was mflixAppUser:mflixAppPwd. Not that this should influence the DNS lookup but may an authentication error is not reported correctly.

You can setup any password you want I imagine and yes they are correct

anyway I did this:

  1. Then create the MongoDB database user required for this course:
  • username: m220student
  • password: m220password

Could you try with the old style URI? In your case it should be

mongodb://User:Password@mflix-shard-00-00-esgqq.mongodb.net:27017,mflix-shard-00-01-esgqq.mongodb.net:27017,mflix-shard-00-02-esgqq.mongodb.net:27017/test?authSource=admin&gssapiServiceName=mongodb&replicaSet=mflix-shard-0&ssl=true
1 Like

yesp it works with this old style URI, do you know the reason?

I really have no idea.

1 Like

Ok it seems that this old URI is valid for the java mongo driver 3.4. or older, from 3.6 or later is changed into the other one. Thanks a lot for your support. Cheers

1 Like

Yes that is the case. But when I took the course I was able to specify the SRV connection string.

For some reason, I cannot connect with the shell with the SRV connection string? But you wrote you could. Have you changed the name of the replica set after you created the cluster.