开发者社区> 问答> 正文

spring-data-mongodb配置用户名和密码报错!:报错

在用spring-data-mongodb配置数据源的,执行相关数据库操作的时候报错,错误如下


org.springframework.data.mongodb.CannotGetMongoDbConnectionException: Failed to authenticate to database [ashop], username = [ashop], password = [g***********4]
	org.springframework.data.mongodb.core.ReflectiveDbInvoker.authenticate(ReflectiveDbInvoker.java:83)
	org.springframework.data.mongodb.core.MongoDbUtils.doGetDB(MongoDbUtils.java:127)
	org.springframework.data.mongodb.core.MongoDbUtils.getDB(MongoDbUtils.java:94)
	org.springframework.data.mongodb.core.SimpleMongoDbFactory.getDb(SimpleMongoDbFactory.java:203)
	org.springframework.data.mongodb.core.SimpleMongoDbFactory.getDb(SimpleMongoDbFactory.java:191)
	org.springframework.data.mongodb.core.MongoTemplate.getDb(MongoTemplate.java:1606)
	org.springframework.data.mongodb.core.MongoTemplate.executeFindOneInternal(MongoTemplate.java:1839)
	org.springframework.data.mongodb.core.MongoTemplate.doFindOne(MongoTemplate.java:1656)
	org.springframework.data.mongodb.core.MongoTemplate.findOne(MongoTemplate.java:564)
	org.springframework.data.mongodb.core.MongoTemplate.findOne(MongoTemplate.java:559)
	com.oneday.ashop.core.base.mongo.BaseMongoDaoSupport.findOne(BaseMongoDaoSupport.java:81)
	com.oneday.ashop.webgate.user.UserDao.findUser(UserDao.java:44)
	com.oneday.ashop.webgate.user.UserService.login(UserService.java:88)
	com.oneday.ashop.webgate.user.UserControl.login(UserControl.java:57)
	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	java.lang.reflect.Method.invoke(Unknown Source)
	org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
	org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
	org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
	org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:776)
	org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:705)
	org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
	org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:868)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
但是同样的地址、端口、数据库实例的名称、用户名、密码,用工具就能登陆上,


我的jar包版本是这样的:

然后的配置文件是这样的

如果有对这个比较了解,希望指导一下!

展开
收起
kun坤 2020-06-06 11:41:09 763 0
1 条回答
写回答
取消 提交回答
  • http://stackoverflow.com/questions/30112157/spring-mongodb-authorization-failed

    2020-06-06 11:41:16
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Data as a Service - 数据即服务 -- MongoDB⾼级应⽤模式 立即下载
阿里云MongoDB云服务构建 立即下载
饿了么高级架构师陈东明:MongoDB是如何逐步提高可靠性的 立即下载