2015-07-14 4 views
2

Я пытаюсь использовать mongodb с grails. Для этого добавьте следующий код в плагине части в BuildConfig.groovyКак использовать mongodb с grails 2.4.4?

compile ":mongodb:3.0.3" 

Тогда я изменил DataSource.groovy в follwings:

  grails { 
      mongo { 
       host = "localhost" 
       port = 27107 
       username = "user" 
       password="secretpassword" 
       databaseName = "physicians" 
      } 
      } 

Но это вызывает ошибку компиляции, как следующие:

Error | 
2015-07-14 14:29:53,412 [localhost-startStop-1] ERROR context.GrailsContextLoaderListener - Error initializing the application: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'mongoTransactionManager' while setting constructor argument with key [1]; nested exception is org.springframework.beans.factory.BeanCreationException: 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': Cannot resolve reference to bean 'mongoBean' while setting bean property 'mongo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongo': Invocation of init method failed; nested exception is com.mongodb.MongoTimeoutException: Timed out while waiting for a server that matches AnyServerSelector{} after 10000 ms 
Message: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'mongoTransactionManager' while setting constructor argument with key [1]; nested exception is org.springframework.beans.factory.BeanCreationException: 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': Cannot resolve reference to bean 'mongoBean' while setting bean property 'mongo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongo': Invocation of init method failed; nested exception is com.mongodb.MongoTimeoutException: Timed out while waiting for a server that matches AnyServerSelector{} after 10000 ms 
    Line | Method 
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
| 166 | run  in java.util.concurrent.FutureTask 
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor 
| 615 | run  in java.util.concurrent.ThreadPoolExecutor$Worker 
^ 724 | run . . . in java.lang.Thread 
Caused by BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'mongoTransactionManager' while setting constructor argument with key [1]; nested exception is org.springframework.beans.factory.BeanCreationException: 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': Cannot resolve reference to bean 'mongoBean' while setting bean property 'mongo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongo': Invocation of init method failed; nested exception is com.mongodb.MongoTimeoutException: Timed out while waiting for a server that matches AnyServerSelector{} after 10000 ms 
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
| 166 | run  in java.util.concurrent.FutureTask 
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor 
| 615 | run  in java.util.concurrent.ThreadPoolExecutor$Worker 
^ 724 | run . . . in java.lang.Thread 
Caused by BeanCreationException: 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': Cannot resolve reference to bean 'mongoBean' while setting bean property 'mongo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongo': Invocation of init method failed; nested exception is com.mongodb.MongoTimeoutException: Timed out while waiting for a server that matches AnyServerSelector{} after 10000 ms 
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
| 166 | run  in java.util.concurrent.FutureTask 
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor 
| 615 | run  in java.util.concurrent.ThreadPoolExecutor$Worker 
^ 724 | run . . . in java.lang.Thread 
Caused by BeanCreationException: Error creating bean with name 'mongoDatastore': Cannot resolve reference to bean 'mongoBean' while setting bean property 'mongo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongo': Invocation of init method failed; nested exception is com.mongodb.MongoTimeoutException: Timed out while waiting for a server that matches AnyServerSelector{} after 10000 ms 
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
| 166 | run  in java.util.concurrent.FutureTask 
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor 
| 615 | run  in java.util.concurrent.ThreadPoolExecutor$Worker 
^ 724 | run . . . in java.lang.Thread 
Caused by BeanCreationException: Error creating bean with name 'mongo': Invocation of init method failed; nested exception is com.mongodb.MongoTimeoutException: Timed out while waiting for a server that matches AnyServerSelector{} after 10000 ms 
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
| 166 | run  in java.util.concurrent.FutureTask 
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor 
| 615 | run  in java.util.concurrent.ThreadPoolExecutor$Worker 
^ 724 | run . . . in java.lang.Thread 
Caused by MongoTimeoutException: Timed out while waiting for a server that matches AnyServerSelector{} after 10000 ms 
->> 87 | getServer in com.mongodb.BaseCluster 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
| 654 | getServer in com.mongodb.DBTCPConnector 
|  39 | access$300 in  '' 
| 503 | getConnection in com.mongodb.DBTCPConnector$MyPort 
| 451 | get . . . in  '' 
| 624 | authenticate in com.mongodb.DBTCPConnector 
| 195 | doAuthenticate in com.mongodb.DBApiLayer 
| 765 | authenticateCommandHelper in com.mongodb.DB 
| 721 | authenticate in  '' 
| 149 | afterPropertiesSet in org.grails.datastore.gorm.mongo.bean.factory.GMongoFactoryBean 
| 334 | innerRun in java.util.concurrent.FutureTask$Sync 
| 166 | run  in java.util.concurrent.FutureTask 
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor 
| 615 | run  in java.util.concurrent.ThreadPoolExecutor$Worker 
^ 724 | run . . . in java.lang.Thread 
Error | 
Forked Grails VM exited with error 

Не могли бы вы рассказать мне, как исправить ошибку. Кстати, учебник, что я следовал, можно найти в ссылке ниже: http://blog.mongodb.org/post/18510469058/grails-in-the-land-of-mongodb

ответ

0

ваш сервер недоступен, то, что вы можете ясно видеть в трассировке исключения:

причиненного MongoTimeoutException: Таймаут во время ожидания сервера, который соответствует AnyServerSelector {} через 10000 мс

+0

Я новичок в граале. не могли бы вы рассказать мне, что делать, чтобы решить эту проблему? –

+0

убедитесь, что сервер mongo запущен и доступен через 'localhost: 27107'. – injecteer

0

Так вот что происходит:

Прежде всего вы должны подтвердить, если ваш монг o работает только путем ввода команды mongo (и посмотреть, приземлитесь ли вы на монгольскую оболочку) или на ps -A | grep mongod.

В любом случае, если служба MongoDB запущена, вам сначала нужно начать обслуживание.

sudo service mongod start # Для Ubuntu & CentOS
# ИЛИ
mongod --config /etc/mognod.conf

(Я дал вам пример для Ubuntu & CentOS. Read this если вы используете другую операционную систему.)

Теперь, после того, как вы начали службу или подтвердили, что сервер MongoDB работает &, вам нужно выполнить run-app.

Одна вещь, которую я видел в вашем вопросе в номере порта, например, 27107, а не 27017. Я не уверен, что это по ошибке в вопросе, или вы добавили это в свой файл Grails DataSource.groovy. По умолчанию MongoDB запускается на номер порта 27017 (хотя вы можете его настроить). Так что это может быть вашей проблемой.

Поэтому измените этот номер порта на 27017, а затем выполните grails run-app. Это должно сработать.

Смежные вопросы