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 ...
随机推荐
- Jmeter(8)分布式测试
通过Jmeter远程启动功能,把一台windows机器作为控制器,远程控制其他多个Windows或linux压力机,把压力分散到多台执行机器上,从而实现高并发,并在控制机上搜集测试结果 Jmeter分 ...
- MyBatis史上最全文章
老规矩,本篇文章 不做 MyBatis 的 编码讲解 ,只介绍 文章学习的一些优秀文章 重点在于不要循规蹈矩,教程 这样走,你不一定要按他这样走,按自己的方式来,学习效率会更高,网上的教程有很多,今天 ...
- 制作3D小汽车游戏(上)
之前一段时间家里和公司的事太多,一直没有时间写博客,最近腾出一段时间,看了一遍官方的examples,收货颇多,想整理一点东西出来,又苦于没有好的东西,three写点东西真是太难了.好吧,今天郭先生就 ...
- 你真的理解了java单例模式吗?讲别人都忽略的细节!
前言:老刘这篇文章敢做保证,java的单例模式讲的比大多数的技术博客都要好,讲述别人技术博客都没有的细节!!! 1 java单例模式 直接讲实现单例模式的两种方法:懒汉式和饿汉式,单例模式的概念自己上 ...
- Dovecot邮件服务器的正确安装方法
Dovecot邮件服务器的正确安装方法 apt remove dovecot-coredpkg -P dovecot-core sudo apt install dovecot-imapd dovec ...
- Pygame的简单总结
Pygame learn from mooc 私货:在调用函数时,可以 1.import tkinter (不过在使用时还要加前缀如tkinter.Tk()) 2.import tkinter as ...
- 高性能MySQL学习总结一
一.MySQL逻辑架构 第一层的服务不是MySQL独有的,大多数是基于网络的客户端/服务端的工具,如连接处理.授权认证.安全等等. 第二层就是MySQL的核心功能,包括查询解析.分析.优化.缓存以及所 ...
- MybatisPlus学习(四)条件构造器Wrapper方法详解
文章目录 1.条件构造器 2.QueryWrapper 2.1.eq.ne 2.2.gt.ge.lt.le 2.3.between.notBetween 2.4.like.notLike.likeLe ...
- mybatis实现MySQL数据库的增删改查
环境: jdk1.8 mysql5.7 maven3.6.0 IDEA 什么是mybatis框架? MyBatis 是一款优秀的持久层框架, 它支持自定义 SQL.存储过程以及高级映射. MyBati ...
- java数组之system.arrayCopy
public class ArrayDemo { /* public static void main(String[] args) { int[] a=new int[4]; int[] b=new ...