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 ...
随机推荐
- Android开源项目-转载
一.视频播放 https://github.com/lipangit/JieCaoVideoPlayer 二.图片选择 https://github.com/pengjianbo/GalleryFin ...
- 官方VisualStudio.gitignore配置
官方地址 https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 示例 ## Ignore Visual Stud ...
- Python 最简单的数字相乘
风变编程第18关,快要结束了,捎带着复习了一下前面的基础.结果悲剧了. 打开题目是这样的: 比如我们想写一个根据圆的半径(R)来求面积(S)和周长(L)的代码,可以画出以下的流程图 抬眼一看,好简单的 ...
- 【mybatis-plus】主键id生成、字段自动填充
一.主键id的生成 数据库表里通常都会有一个主键id,来作为这条数据的唯一标识. 常见的方式 数据库自动增长 这种很常见了,可以做到全库唯一.因为id是天然排序的,对于涉及到排序的操作会很方便. UU ...
- 磁盘IO工作机制
磁盘IO工作机制 ref: <深入分析java web 技术内幕> by:许令波 几种访问文件的方式 文件读取和写入的 IO 操作都是调用操作系统提供的接口,因为磁盘设备是由操作系统管理的 ...
- [leetcode350]Intersection of Two Arrays II求数组交集
List<Integer> res = new ArrayList<>(); Arrays.sort(nums1); Arrays.sort(nums2); int i1 = ...
- WIN10系统下静态编译Qt4.8.7
qt-everywhere-opensource-src-4.8.7.tar.gz http://download.qt.io/archive/qt/4.8/4.8.7/qt-everywhere- ...
- “开源、共享、创新” 2020 中国.NET开发者大会小结
大会的新闻稿在2020年12月31日正式发布:开源·共享·创新|2020年中国.NET开发者大会圆满收官! , 本文是这篇新闻的补充性文章,仅代表个人对大会的各方面分享内容的一个小结. 在2019年上 ...
- FAAS -- Serverless
FAAS概念,无服务器运算,功能即服务,function-as-a-service 初创企业-大型企业.民间组织-政府机构 ===>>>> 上云 云计算第三代技术 -- Ser ...
- 大数据可视化呈现工具LightningChart的用法
LightningChart (LightningChart Ultimate) 软件开发工具包是微软VisualStudio 的一个插件,专攻大数据可视化呈现问题,用于WPF(WindowsPres ...