Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8579179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:33:25+00:00 2026-06-11T20:33:25+00:00

Getting following error while connecting to mongodb using Spring Data: java.io.IOException: couldn’t connect to

  • 0

Getting following error while connecting to mongodb using Spring Data:

java.io.IOException: couldn't connect to [/127.0.0.1:27017] bc:java.net.ConnectException: Connection refused: connect
at com.mongodb.DBPort._open(DBPort.java:228)
at com.mongodb.DBPort.go(DBPort.java:112)
at com.mongodb.DBPort.call(DBPort.java:79)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:218)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:305)
at com.mongodb.DB.getCollectionNames(DB.java:284)
at org.springframework.data.mongodb.core.MongoTemplate$14.doInDB(

Please find my configuration :

@Configuration
public class AppConfig {

public @Bean MongoOperations mongoTemplate(Mongo mongo) {
    MongoTemplate mongoTemplate = new MongoTemplate(mongo, "mydb");
    return mongoTemplate;
}

/*
 * Factory bean that creates the Mongo instance
 */
public @Bean MongoFactoryBean mongo() {
    MongoFactoryBean mongo = new MongoFactoryBean();
    mongo.setHost("10.6.120.180");
    mongo.setPort(27017);
    return mongo;
}

/*
 * Use this post processor to translate any MongoExceptions thrown in @Repository annotated classes
 */
public @Bean PersistenceExceptionTranslationPostProcessor persistenceExceptionTranslationPostProcessor() {
    return new PersistenceExceptionTranslationPostProcessor();
}

}

Mongo-context-test.xml

    <mongo:db-factory dbname="mydb"/>
    <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
    <constructor-arg ref="mongoDbFactory"/>
</bean>

I am new to Spring Data and MongoDB. Please advice, why am I getting this error?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:33:26+00:00Added an answer on June 11, 2026 at 8:33 pm

    Are you sure that your AppConfig class is being used?

    As mentioned in my comment the error you are receiving indicates that your program is attempting to connect to MongoDB on server 127.0.0.1 while the AppConfig class you have posted clearly shows that you want to connect to IP address 10.6.120.180.

    This can happen if you are somehow picking up an AppConfig class that contains mongo.setHost("localhost") which is in the example code posted on Github.

    Update: Based on OP’s comment the class reference for mongoTemplate in Mongo-context-test.xml was pointing to the Spring Framework’s default MongoTemplate class.

    According to the SpringSource documentation Introduction to MongoTemplate use can use Java to create and register an instance of MongoTemplate OR configure a MongoTemplate using Spring’s XML <beans/> schema.

    Obviously using the <beans/> schema takes precedence over your implementation in Java. If you use the <beans/> schema then you need to use <mongo:mongo host="localhost" port="27017"/> to specify your host and port requirements as noted by the OP in his comment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

while using tiles along with spring i m getting following error: java.net.UnknownHostException: tiles.apache.org program
i am getting following error while getting data from dictionary -[__NSCFString objectForKey:]: unrecognized selector
I have done simple java app for blackberry, while building am getting following error.
I'm getting the following error, while using ExtJs MVC, Uncaught TypeError: Cannot call method
I am getting the following error while using ApiKeyAuthentication for my Tastypie resources when
I am getting following error while I am connecting my iPhone to organizer. I
While using the Rotten Tomatoes API I am getting the following error: org.json.JSONException: Value
I'm getting the following error while connecting to my SQL database: function mysql_query($query) {
I am getting following error while installing the application on my device. before running
I am getting the following error while compiling a sample program in Qt 4.5

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.