Uploaded image for project: 'MongoDB Database Tools'
  1. MongoDB Database Tools
  2. TOOLS-1412

How to set connection string with xml in Java spring application

    • Type: Icon: Question Question
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None

      I have the below bean configured in my application.

      <bean id="mongo" class="org.springframework.data.mongodb.core.MongoFactoryBean">
      <property name="host" value="<host>.xyz.net" />
      <property name="port" value="27130" />
      </bean>

      <mongo:db-factory dbname="testdb" mongo-ref="mongo" />

      <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
      <constructor-arg name="mongoDbFactory" ref="mongoDbFactory" />
      <constructor-arg name="mongoConverter" ref="mappingMongoConverter" />
      </bean>

      <bean id="mappingContext" class="org.springframework.data.mongodb.core.mapping.MongoMappingContext" />

      <bean id="defaultMongoTypeMapper" class="org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper">
      <constructor-arg name="typeKey"><null/></constructor-arg>
      </bean>

      <bean id="mappingMongoConverter" class="org.springframework.data.mongodb.core.convert.MappingMongoConverter">
      <constructor-arg name="mongoDbFactory" ref="mongoDbFactory" />
      <constructor-arg name="mappingContext" ref="mappingContext" />
      <property name="typeMapper" ref="defaultMongoTypeMapper" />
      </bean>

      I am using mongo java driver 3.0.3. We are getting the below error.

      Unable to connect to any servers; nested exception is com.mongodb.MongoServerSelectionException: Unable to connect to any servers

      com.bnymellon.inp.exceptions.MyIdeaException: Unable to connect to any servers; nested exception is com.mongodb.MongoServerSelectionException: Unable to connect to any servers

      Could you please provide me a sample bean ?

      Please advise.

            Assignee:
            gabriel.russell@mongodb.com Gabriel Russell (Inactive)
            Reporter:
            ChandranMuthu Chandran Muthu [X]
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: