使用名称' mongoTransactionManager'创建bean时出错:无法解析对bean的引用&mongoDatastore'设置bean属性'数据存储区'

时间:2015-08-10 06:12:02

标签: java mongodb grails groovy

我正在尝试将Grails项目与MongoDB连接,但收到以下错误

使用名称' mongoTransactionManager'创建bean时出错:无法解析对bean的引用&m ;; mongoDatastore'设置bean属性'数据存储'

我的DataSource.groovy文件 -

    grails{
        mongo{
            host ="127.0.0.1"
            port ="27017"
            username = "blogproject"
            password = "mypassword"
            databaseName ="blogproject"
        }
    }

我已从BuildConfig.groovy中删除了以下内容

//runtime ":hibernate:3.6.10.12" 
//runtime ":database-migration:1.3.8"
//compile ':cache:1.1.1'

并在BuildConfig.groovy

中添加了以下内容
   compile ":mongodb:3.0.3"

我的错误堆栈跟踪如下 -

Error |
2015-08-10 11:17:15,002 [localhost-startStop-1] ERROR context.GrailsContextLoader  - Error initializing the application: Error creating bean with name 'mongoTransactionManager': Cannot resolve reference to bean 'mongoDatastore' while setting bean property 'datastore'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoDatastore': FactoryBean threw exception on object creation; nested exception is org.springframework.data.mongodb.CannotGetMongoDbConnectionException: Failed to authenticate to database [blogproject], username = [blogproject], password = [m*********d]
Message: Error creating bean with name 'mongoTransactionManager': Cannot resolve reference to bean 'mongoDatastore' while setting bean property 'datastore'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoDatastore': FactoryBean threw exception on object creation; nested exception is org.springframework.data.mongodb.CannotGetMongoDbConnectionException: Failed to authenticate to database [blogproject], username = [blogproject], password = [m*********d]
    Line | Method
->>  334 | innerRun  in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    166 | run       in java.util.concurrent.FutureTask
|   1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    603 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run . . . in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'mongoDatastore': FactoryBean threw exception on object creation; nested exception is org.springframework.data.mongodb.CannotGetMongoDbConnectionException: Failed to authenticate to database [blogproject], username = [blogproject], password = [m*********d]
->>  334 | innerRun  in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    166 | run       in java.util.concurrent.FutureTask
|   1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    603 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run . . . in java.lang.Thread
Caused by CannotGetMongoDbConnectionException: Failed to authenticate to database [blogproject], username = [blogproject], password = [m*********d]
->>  285 | initializeIndices in org.grails.datastore.mapping.mongo.MongoDatastore
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    276 | createMongoTemplate in     ''
|    221 | afterPropertiesSet in     ''
|     54 | getObject in org.grails.datastore.gorm.mongo.bean.factory.MongoDatastoreFactoryBean
|    334 | innerRun  in java.util.concurrent.FutureTask$Sync
|    166 | run       in java.util.concurrent.FutureTask
|   1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    603 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run . . . in java.lang.Thread
|Server running. Browse to http://localhost:8090/blogproject
Error |
Forked Grails VM exited with error

我还在MongoDB中添加了以下用户数据库" blogproject"用于身份验证

> use blogproject
switched to db blogproject
> show users;
{
        "_id" : "blogproject.blogproject",
        "user" : "blogproject",
        "db" : "blogproject",
        "roles" : [
                {
                        "role" : "readWrite",
                        "db" : "blogproject"
                },
                {
                        "role" : "dbAdmin",
                        "db" : "blogproject"
                },
                {
                        "role" : "dbOwner",
                        "db" : "blogproject"
                },
                {
                        "role" : "userAdmin",
                        "db" : "blogproject"
                }
        ]
}
>

1 个答案:

答案 0 :(得分:0)

看起来用户名和/或密码错误:

Failed to authenticate to database [blogproject], username = [blogproject], password = [m*********d]