springboot 和 mongdb连接问题 Exception in thread "main" com.mongodb.MongoSecurityException:
1 Exception in thread "main" com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='user', source='userdb', password=<hidden>, mechanismProperties={}}
2 Caused by: com.mongodb.MongoCommandException: Command failed with error 18 (AuthenticationFailed): 'Authentication failed.' on server 你的IP:你的端口. The full response is { "ok" : 0.0, "errmsg" : "Authentication failed.", "code" : 18, "codeName" : "AuthenticationFailed" }
出现以上springboot 2.x连接 mongdb 3.x的情况。
直面意思,就是指认证失败。
情况有4种,
1.你的认证方式有问题
2.认证信息有误(用户名密码等配错了)
3.mongodb数据库问题
4.springboot yml配置错误
1.你的认证方式有问题
SCRAM-SHA-1:就是mongodb 3.x之后默认的认证方式,springboot 2.x之后也是可以选择这种方式。
注意:mechanism=SCRAM-SHA-1。如果你不是这种方式,你就要升级你的springboot版本,或者去修改你的mongdb数据库的认证方式/降低mongodb版本。
你用纯javamongodb-driver包测试时,可见com.mongodb.MongoCredential 类下选取的认证方式来源于如下类。
public enum AuthenticationMechanism {
GSSAPI("GSSAPI"),
PLAIN("PLAIN"),
MONGODB_X509("MONGODB-X509"),
/** @deprecated */
@Deprecated
MONGODB_CR("MONGODB-CR"),
SCRAM_SHA_1("SCRAM-SHA-1"),
SCRAM_SHA_256("SCRAM-SHA-256");
private static final Map<String, AuthenticationMechanism> AUTH_MAP = new HashMap();
private final String mechanismName;
private AuthenticationMechanism(String mechanismName) {
this.mechanismName = mechanismName;
}
2.认证信息有误(用户名密码等配错了)
如果你手动,改错 数据库名或者用户名密码,你会发现也是会报这个错误。
3.mongdb数据库问题
用户权限问题。正确的用户创建如下:
use mydb
#没有数据库会自动创建 #在此数据库下创建用户
db.createUser(
{
user: "user",
pwd: "123456",
roles: [ { role: "readWrite", db: "mydb" } ]
}
) #重新进入,开启auth参数,认证通过后才能访问数据库
./mongod -f mongdb.conf --auth db.auth("user","123456") 认证通过后可以操作数据库。
4.springboot yml配置错误
spring:
application:
name: test
data:
mongodb:
host: 你的Ip
username: user
password: 123456
database: user
port: 1234 #如果你是上面这种配置方式,那么恭喜你。他根本不会成功
#正确配置是如下这种方式
uri: mongodb://user:123456@你的Ip:1234/user
springboot 和 mongdb连接问题 Exception in thread "main" com.mongodb.MongoSecurityException:的更多相关文章
- windows下eclipse远程连接hadoop错误“Exception in thread"main"java.io.IOException: Call to Master.Hadoop/172.20.145.22:9000 failed ”
在VMware虚拟机下搭建了hadoop集群,ubuntu-12.04,一台master,三台slave.hadoop-0.20.2版本.在 master机器上利用eclipse-3.3连接hadoo ...
- 使用sqljdbc连接mssql数据库,maven生成jar运行后报"Exception in thread "main" java.lang.SecurityException"错误
错误信息如下: Exception in thread "main" java.lang.SecurityException: Invalid signature file dig ...
- 在运行Hibernate Hello World程序的时候,抛如下错误: view plain Exception in thread "main" org.hibernate.exception.LockAcquisitionException 解决方法
在运行Hibernate Hello World程序的时候,抛如下错误: Exception in thread "main" org.hibernate.exception.Lo ...
- ReactNative问题随记1 Exception in thread "main" java.lang.RuntimeException: gradle-2.14.1-all.zip
ReactNative问题随记 想运行在真机上,在运行命令react-native run-android遇到错误如下: Scanning 559 folders for symlinks in D: ...
- yml配置文件读取出错 Exception in thread "main" while scanning for the next token found character '\t(TAB)'
这几天在学习springboot的微服务项目,在配置文件方面也想尝试下新的yml配置,就想把原来项目properties写的文件转换成yml试一下(老项目是之前检出在了eclipse里面),结果写好了 ...
- Exception in thread "main" java.lang.UnsupportedClassVersionError : unsupported major.minor version 52.0
新建好springboot项目后,打开application运行main方法报如下错. 1.问题:Exception in thread "main" java.lang.Unsu ...
- Exception in thread "main" java.net.SocketTimeoutException: connect timed ou错误处理
今天做了一个Jsoup解析网站的项目,使用Jsoup.connect(url).get()连接某网站时偶尔会出现java.net.SocketTimeoutException:Read timed o ...
- Exception in thread "main" java.nio.channels.NotYetConnectedException
import java.nio.channels.AsynchronousServerSocketChannel; import java.nio.channels.AsynchronousSocke ...
- Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused (Connection refused)
一.linux中配置redis,使用java连接测试时报错: Exception in thread "main" redis.clients.jedis.exceptions.J ...
随机推荐
- Angular学习知识点记录
问:版本直接跳转到Angular4? 答:为了遵循严格的版本策略.在angular2.x的时候,angular route的版本已经是版本3了.因此为了版本统一,angular直接从2跳到了4,.参考 ...
- html文本域textarea高度自增、自动换行
文本域自动换行.高度自增,采用以下方式: html: <textarea rows="1" class="answerTextArea" maxlengt ...
- mysql位函数的使用
查询每个月的访问天数 mysql> create table t1 (year YEAR(4),month int(2) unsigned zerofill,day int(2) u nsign ...
- Web服务器-服务器开发-返回浏览器需要的页面 (3.3.2)
@ 目录 1.说明 2.代码 关于作者 1.说明 使用正则表达式,匹配客户端的请求头 获取到请求的路径 返回对应请求路径的文字 可以使用打开对应文件的方式去返回对应的文件 2.代码 from sock ...
- SpringCloud 的版本问题 (深入)
学过SpringCloud 的 同学 ,就应该知道,SpringCloud是一个生态 . Spring Cloud是一个由众多独立子项目组成的大型综合项目,每个子项目都维护着自己的发布版本号.Spri ...
- k8s ansible部署部署文档
一:基础系统准备 ubuntu 1804----> root密码:123456 主要操作: 1.更改网卡名称为eth0: # vim /etc/default/grub GRUB_CMDLI ...
- Python 搜索文件,文件过滤,pathlib模块
1,搜索文件,文件过滤 这里使用:pathlib 模块的 Path.glob(pattern) 方法,该方法可以用来过滤目标文件,以迭代器的形式返回搜索结果. pattern: 通配符:" ...
- 卡尔曼滤波学习笔记1-Matlab模拟温度例子--代码比较乱,还需优化
温度模拟参数选取 xk 系统状态 实际温度 A 系统矩阵 温度不变,为1 B.uk 状态的控制量 无控制量,为0 Zk 观测值 温度计读数 H 观测矩阵 直接读出,为1 wk 过程噪声 温度变化偏差, ...
- Semaphore信号量深度解析
1. 使用指南 package com.multthread; import java.util.concurrent.ExecutorService; import java.util.concur ...
- GitLab CI构建SpringBoot-2.3应用
欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...