0

I'm trying to connect MongoDB using Spring xml configuration i'm getting this error:

INFO : org.mongodb.driver.cluster - Exception in monitor thread while connecting to server 192.168.1.7:27071 com.mongodb.MongoSocketOpenException: Exception opening socket

web.xml

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

servlet-context.xml

<beans:beans>
    <mongo:mongo host="192.168.1.7" port="27071"></mongo:mongo>

    <beans:bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
        <beans:constructor-arg ref="mongo"></beans:constructor-arg>
        <beans:constructor-arg value="admin"></beans:constructor-arg>
    </beans:bean>
    <mongo:repositories base-package="com.excelit.login"></mongo:repositories>
</beans:bean>
DimaSan
  • 12,264
  • 11
  • 65
  • 75
pooja J
  • 21
  • 3
  • Are you sure that mongo is listening on that port / interface? Have you set the bind_ip? – Patrick Bray Jun 20 '17 at 11:32
  • Yes, mongo is listening on that port.but I am getting this exception: INFO : org.mongodb.driver.cluster - Exception in monitor thread while connecting to server 192.168.1.7:27071 com.mongodb.MongoSocketOpenException: Exception opening socket at com.mongodb.connection.SocketStream.open(SocketStream.java:63) – pooja J Jun 20 '17 at 11:39
  • Are you running this app on the same machine as your mongo service? What is the mongodb bind_ip set to? https://docs.mongodb.com/manual/reference/configuration-options/#net.bindIp – Patrick Bray Jun 20 '17 at 11:44
  • sorry by mistake I have given port ="27071" instead of port="27017"....Now connection is happening Thank You. – pooja J Jun 21 '17 at 05:31

0 Answers0