无法从springboot应用程序

时间:2016-04-05 12:52:14

标签: java mongodb spring-boot spring-data-mongodb mongodb-java

我正在使用spring启动应用程序来连接MongoDB实例。我们已在MongoDB上启用了具有以下角色的身份验证

  

角色:[{role:" dbOwner",db:" {{mongo.database_name}}" }

     

角色:[{role:" readWrite",db:" {{mongo.database_name}}" }

我们使用conf文件提供凭证

  

数据:

     

mongodb.uri:mongodb://127.0.0.1/testDB

     

mongodb.authentication-database:admin

     

mongodb.username:' admin'

     

mongodb.password:' admin'

     

repositories.enabled:true

在启动应用程序时,我们正在插入特定的集合。但是在插入过程中,它尝试创建索引并失败并出现以下异常

org.springframework.data.mongodb.UncategorizedMongoDbException:  {" serverUsed" :" localhost:27017" ," ok" :0.0," errmsg" :"未在testDB上授权执行命令  {createIndexes:\" ws.city \",索引:[{name:\" code \",ns:\" testDB.ws.city \&# 34;,unique:true,key:{code:1}}]}" ,"代码" :13};

完整的堆栈跟踪:

  

通过带有[XYZRepository]类型的索引0的构造函数参数表示的不满意的依赖:    :创建名称为' XYZRepository'的init时出错:init方法的调用失败;    嵌套异常是org.springframework.data.mongodb.UncategorizedMongoDbException:    {" serverUsed" :" localhost:27017" ," ok" :0.0," errmsg" :"未在testDB上授权执行命令    {createIndexes:\" ws.city \",索引:[{name:\" code \",ns:\" testDB.ws.city \&# 34;,unique:true,key:{code:1}}]}" ,"代码" :13};     嵌套异常是com.mongodb.CommandFailureException:{" serverUsed" :" localhost:27017" ," ok" :0.0,     " ERRMSG" :"未在testDB上授权执行命令{createIndexes:\" ws.city \",索引:[{name:\" code \",ns:\ " testDB.ws.city \",unique:true,key:{code:1}}]}" ,"代码" :13};     嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名称为' XYZRepository'的bean时出错:     调用init方法失败;嵌套异常是org.springframework.data.mongodb.UncategorizedMongoDbException:     {" serverUsed" :" localhost:27017" ," ok" :0.0,     " ERRMSG" :"未在testDB上授权执行命令{createIndexes:\" ws.city \",索引:[{name:\" code \",ns:\ " testDB.ws.city \",unique:true,key:{code:1}}]}" ,"代码" :13};     嵌套异常是com.mongodb.CommandFailureException:{" serverUsed" :" localhost:27017" ," ok" :0.0," errmsg" :"未在testDB上授权执行命令      {createIndexes:\" ws.city \",索引:[{name:\" code \",ns:\" testDB.ws.city \&# 34;,unique:true,key:{code:1}}]}" ,"代码" :13}       在org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749)       在org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:185)       在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1143)       在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1046)       在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)       在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)       at org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:306)       在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)       在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)       在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)       at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)       at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)       在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)       at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)       在org.springframework.boot.SpringApplication.refresh(SpringApplication.java:764)       在org.springframework.boot.SpringApplication.doRun(SpringApplication.java:357)       在org.springframework.boot.SpringApplication.run(SpringApplication.java:305)       在org.springframework.boot.SpringApplication.run(SpringApplication.java:1124)       在org.springframework.boot.SpringApplication.run(SpringApplication.java:1113)       在com.app.ws.WSApplication.main(WSApplication.java:22)       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)       at java.lang.reflect.Method.invoke(Method.java:498)       在org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)       在java.lang.Thread.run(Thread.java:745)

理想情况下,我理解应用程序与mongodb交互所需的角色应该是" readWrite"。

  • 它是否期望有不同的角色?
  • 春天是否会尝试在插入时自动创建索引并需要更高/不同的角色?

  • 在这种情况下我们缺少什么?

我们正在使用mongoDB最新版本:3.2.4 Springboot 1.3.1

2 个答案:

答案 0 :(得分:3)

尝试将身份验证数据库更改为testdb,如mongodb.authentication-database: testDB

答案 1 :(得分:0)

answer对我有用,因为我是一个独立的mongo,请参阅docs,有关执行访问控制的独立项目。

join