<!-- 不需要密码验证的配置方式 -->
  <mongo:mongo-client host="127.0.0.1" port="27017">
    <mongo:client-options write-concern="NORMAL" />
  </mongo:mongo-client>

   <!-- spring连接mongodb数据库的配置 需要密码验证的方式 tuzongxun:123456@mongoTest 对应用户,密码 数据库 -->  
    <mongo:mongo-client host="192.168.0.201" port="27017" credentials="tuzongxun:123456@mongoTest" id="mongo">    
       <mongo:client-options write-concern="SAFE"/>    
    </mongo:mongo-client>

如果用了write-concern=”SAFE”,必须要使用用户密码的方式,否则报错: nested exception is java.lang.IllegalArgumentException: Credentials need to specify username!