Announcement Announcement Module
Collapse
No announcement yet.
Mongo DB Connection refuse error Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mongo DB Connection refuse error

    Hi iam running mongodb in my local machine os as ubuntu .
    But when i try to save Contact object iam getting connection error .

    Code:
    @Autowired
        private MongoTemplate mongoTemplate;
         public void insertContact(Contact contact) {
            //get random age between 1 and 100
           System.out.println("montodb" + mongoTemplate + mongoTemplate.getDb().toString()); 
    
            mongoTemplate.save(contact,"collections");
     
            //mongoTemplate.insert(contact);
            
            
        }
    java.io.IOException: couldn't connect to [/127.0.1.1:27017] bc:java.net.ConnectException: Connection refused
    at com.mongodb.DBPort._open(DBPort.java:205)
    at com.mongodb.DBPort.go(DBPort.java:94)
    at com.mongodb.DBPort.go(DBPort.java:75)
    at com.mongodb.DBPort.say(DBPort.java:70)
    at com.mongodb.DBTCPConnector.say(DBTCPConnector.java :160)
    at com.mongodb.DBTCPConnector.say(DBTCPConnector.java :146)
    at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLa yer.java:254)
    at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLa yer.java:209)
    at com.mongodb.DBCollection.insert(DBCollection.java: 66)
    at com.mongodb.DBCollection.save(DBCollection.java:62 4)
    at com.mongodb.DBCollection.save(DBCollection.java:59 9)
    at org.springframework.data.mongodb.core.MongoTemplat e$12.doInCollection(MongoTemplate.java:719)
    at org.springframework.data.mongodb.core.MongoTemplat e.execute(MongoTemplate.java:329)
    at org.springframework.data.mongodb.core.MongoTemplat e.saveDBObject(MongoTemplate.java:715)
    at org.springframework.data.mongodb.core.MongoTemplat e.doSave(MongoTemplate.java:655)
    at org.springframework.data.mongodb.core.MongoTemplat e.save(MongoTemplate.java:645)
    at edu.samples.repository.ContactRepository.insertCon tact(ContactRepository.java:25)
    My configuration as follows
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    	xmlns:context="http://www.springframework.org/schema/context"
    	xmlns:mongo="http://www.springframework.org/schema/data/mongo"
    	xsi:schemaLocation="http://www.springframework.org/schema/context
              http://www.springframework.org/schema/context/spring-context-3.0.xsd
              http://www.springframework.org/schema/data/mongo
              http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
              http://www.springframework.org/schema/beans
              http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
                  <!-- Scan components for annotations within the configured package -->
      <context:component-scan base-package="edu.samples.repository">
        <context:exclude-filter type="annotation" expression="org.springframework.context.annotation.Configuration"/>
      </context:component-scan>
                    <context:annotation-config/>
            <mongo:mongo  host="127.0.1.1" port="27017"/>
    
    	
    	
    	<mongo:db-factory id="mongoDbFactory" dbname="demo" mongo-ref="mongo" />
    
    <bean id="template" class="org.springframework.data.mongodb.core.MongoTemplate">
      <constructor-arg name="mongoDbFactory" ref="mongoDbFactory"/>
    </bean>
    
    
     
    	<!-- To translate any MongoExceptions thrown in @Repository annotated classes -->
    	<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
     
     
    </beans>
    Thanks in advance .

  • #2
    Problem with installation. I use ubuntu sudo apt-get install mongodb before . That was cause the issue , I manually download and set up mongo db .
    Solve all the issues .

    Comment

    Working...
    X