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 ...
随机推荐
- sql 执行语句函数
# sql 语句执行函数 def get_access(request): uid=request cursor=connection.cursor() cursor.execute("se ...
- mysql 8.0 改变数据目录和日志目录(一)
一.背景 原数据库数据目录:/data/mysql3306/data,日志文件目录:/data/mysql3306/binlog 变更后数据库目录:/mysqldata/3306/data,日志文件目 ...
- Jmeter +Maven+jenkins+eclipse 接口自动化测试
背景: 首先用jmeter录制或者书写性能测试的脚本,用maven添加相关依赖,把性能测试的代码提交到github,在jenkins配置git下载性能测试的代码,配置运行脚本和测试报告,配置运行失败自 ...
- Unity2D 人物移动切换人物图片
勾选Constraints_freeze Rotation_z轴锁定,防止碰撞偏移. public float moveSpeed = 3f;//定义移动速度 priv ...
- create-react-app 基于ts项目,使用react-router-dom搭建项目
准备工作 来个react项目 create-react-app 基于TS的项目 ts项目安装后 删除node_modules,重新 yarn install, 不然jsx会报错 安装React-rou ...
- CVE-2019-0708_RDP漏洞利用
可以说是2019年影响比较大的一个漏洞了, 简述下这个漏洞: Windows系列服务器于2019年5月15号,被爆出高危漏洞,该漏洞影响范围较广如: windows2003.windows2008.w ...
- luabind 使用
LuaBind --最强大的Lua C++ Bind 转载:http://www.cppblog.com/deane/articles/49208.html1 介绍LuaBind 是一个帮助你绑定C+ ...
- 中小学生的噩梦:怎样用Python检测抄袭行为?广大中小学生们的美梦就此结束
本教程将介绍如何使用机器学习技术(如word2vec和余弦相似度等),在Python中用几行代码制作抄袭检测器.搭建完成后,抄袭检测器将会从文件中载入学生们的作业,然后通过计算相似度来判断学生有无相互 ...
- HCIP----静态实验
要求: 1.全网可达 2.拓扑中所需地址全部基于192.168.0.0/24划分所得 3.使用静态路由 4.R1有三个环回,需要汇总 5.PC1与PC3属于同一VLAN,PC2和PC4属于同一VLAN ...
- asp.net mvc ajax文件上传
前台页面提交文件 <!DOCTYPE html> <html> <head> <meta name="viewport" content= ...