Spring Data MongoDB XML Configuration failed to Authenticate against Mongo-database
Solution 1:
I made it working in a different way. Here, is the final Spring XML file configuration looks like:
<bean id="myMongoServers" class="java.util.ArrayList">
<constructor-arg>
<list>
<ref bean="myMongoServer" />
</list>
</constructor-arg>
</bean>
<bean id="myMongoServer" class="com.mongodb.ServerAddress">
<constructor-arg type="java.lang.String" name="host" value="localhost" />
<constructor-arg type="int" name="port" value="27017" />
</bean>
<bean id="myMongoCredentials" class="java.util.ArrayList">
<constructor-arg>
<list>
<ref bean="myMongoCredential" />
</list>
</constructor-arg>
</bean>
<bean id="myMongoCredential" class="com.mongodb.MongoCredential">
<constructor-arg name="mechanism" value = "#{T(com.mongodb.AuthenticationMechanism).SCRAM_SHA_1}" />
<constructor-arg type="java.lang.String" name="userName" value="admin" />
<constructor-arg type="java.lang.String" name="source" value="mydb" />
<constructor-arg type="char[]" name="password" value="mypass"/>
</bean>
<!-- MongoClient -->
<bean id="mongo" class="com.mongodb.MongoClient">
<constructor-arg ref="myMongoServers" />
<constructor-arg ref="myMongoCredentials" />
</bean>
<mongo:db-factory id="myConnection" mongo-ref="mongo" dbname="mydb"/>
<mongo:template id="myOps" db-factory-ref="myConnection"/>
<mongo:repositories base-package="com.test.app" mongo-template-ref="myOps" />