gpt4 book ai didi

java - 验证 Mongo DB 时出现异常

转载 作者:行者123 更新时间:2023-11-30 03:21:21 42 4
gpt4 key购买 nike

我在 Mongo DB 中插入记录时遇到异常。

org.springframework.dao.DataAccessResourceFailureException: IOException authenticating the connection; nested exception is com.mongodb.MongoException$Network: IOException authenticating the connection
at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:56)
at org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:1791)
at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:404)
at org.springframework.data.mongodb.core.MongoTemplate.insertDBObject(MongoTemplate.java:879)
at org.springframework.data.mongodb.core.MongoTemplate.doInsert(MongoTemplate.java:709)
at org.springframework.data.mongodb.core.MongoTemplate.insert(MongoTemplate.java:663)
at com.yatra.product.seo.service.mongo.MongoJob.singleInsert(MongoJob.java:76)
at com.yatra.product.seo.service.mongo.MongoJob.myRun(MongoJob.java:96)
at com.yatra.platform.commons.YatraRunable.run(YatraRunable.java:9)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: com.mongodb.MongoException$Network: IOException authenticating the connection
at com.mongodb.DBPort$SaslAuthenticator.authenticate(DBPort.java:915)
at com.mongodb.DBPort.authenticate(DBPort.java:432)
at com.mongodb.DBPort.checkAuth(DBPort.java:443)
at com.mongodb.DBTCPConnector.doOperation(DBTCPConnector.java:207)
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:181)
at com.mongodb.DBCollectionImpl.insertWithWriteProtocol(DBCollectionImpl.java:565)
at com.mongodb.DBCollectionImpl.insert(DBCollectionImpl.java:195)
at com.mongodb.DBCollectionImpl.insert(DBCollectionImpl.java:167)
at com.mongodb.DBCollection.insert(DBCollection.java:93)
at com.mongodb.DBCollection.insert(DBCollection.java:78)
at com.mongodb.DBCollection.insert(DBCollection.java:120)
at org.springframework.data.mongodb.core.MongoTemplate$8.doInCollection(MongoTemplate.java:884)
at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:402)
... 9 more
Caused by: javax.security.sasl.SaslException: Unable to find PBKDF2WithHmacSHA1. [Caused by java.security.NoSuchAlgorithmException: PBKDF2WithHmacSHA1 SecretKeyFactory not available]
at com.mongodb.DBPort$ScramSha1Authenticator$ScramSha1SaslClient.Hi(DBPort.java:829)
at com.mongodb.DBPort$ScramSha1Authenticator$ScramSha1SaslClient.computeClientFinalMessage(DBPort.java:747)
at com.mongodb.DBPort$ScramSha1Authenticator$ScramSha1SaslClient.evaluateChallenge(DBPort.java:681)
at com.mongodb.DBPort$SaslAuthenticator.authenticate(DBPort.java:904)
... 21 more
Caused by: java.security.NoSuchAlgorithmException: PBKDF2WithHmacSHA1 SecretKeyFactory not available
at javax.crypto.SecretKeyFactory.<init>(SecretKeyFactory.java:122)
at javax.crypto.SecretKeyFactory.getInstance(SecretKeyFactory.java:160)
at com.mongodb.DBPort$ScramSha1Authenticator$ScramSha1SaslClient.Hi(DBPort.java:826)
... 24 more

请问有人可以帮忙吗?

谢谢

最佳答案

尽管我们看不到您的代码。有两种可能的方法可以解决此问题。

解决方法:添加以下依赖项

    <dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.52</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15</artifactId>
<version>1.46</version>
</dependency>

并在使用 MongoDB 进行身份验证之前添加此指令 Security.addProvider(new BouncyCaSTLeProvider())

正确方法:

因为,PBKDF2WithHmacSHA1 应该包含在您的 java 安装文件夹中。在我看来,我会检查我的环境变量是否正确。如果您使用 Windows,我还会检查 regedit HKLM/Software/JavaSoft/Java Runtime Environment/ 以确保路径也正确。

关于java - 验证 Mongo DB 时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31260719/

42 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com