Grails:如何正确使用/安装rest插件

时间:2012-03-26 18:46:56

标签: rest grails plugins

我创建了一个新的grails应用并执行grails install-plugin rest。应用构建。现在我将插件页面中的示例:http://grails.org/plugin/rest添加到引导程序中并具有:

import l2http.*
class BootStrap {

  def init = { servletContext ->
    withHttp(uri: "http://www.google.com") {
      def html = get(path : '/search', query : [q:'Groovy'])
      assert html.HEAD.size() == 1
      assert html.BODY.size() == 1
    }
  }
  def destroy = {
  }
}

此崩溃时出现以下错误:

| Loading Grails 2.0.0
| Configuring classpath.
| Environment set to development.....
| Packaging Grails application.....
| Compiling 1 source files.....
| Running Grails application
| Error 2012-03-26 11:41:07,823 [Thread-8] ERROR context.GrailsContextLoader  - Error executing bootstraps: groovy.lang.MissingMethodException: No signature of method: grails.util.Environment.withHttp() is applicable for argument types: (java.util.LinkedHashMap, BootStrap$_closure1_closure3) values: [[uri:http://www.google.com], BootStrap$_closure1_closure3@299cc074]
Message: groovy.lang.MissingMethodException: No signature of method: grails.util.Environment.withHttp() is applicable for argument types: (java.util.LinkedHashMap, BootStrap$_closure1_closure3) values: [[uri:http://www.google.com], BootStrap$_closure1_closure3@299cc074]
Line | Method
->>  290 | evaluateEnvironmentSpecificBlock in grails.util.Environment
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    283 | executeForEnvironment            in     ''
|    259 | executeForCurrentEnvironment . . in     ''
|    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 MissingMethodException: No signature of method: grails.util.Environment.withHttp() is applicable for argument types: (java.util.LinkedHashMap, BootStrap$_closure1_closure3) values: [[uri:http://www.google.com], BootStrap$_closure1_closure3@299cc074]
->>  345 | methodMissing                    in grails.util.Environment$EnvironmentBlockEvaluator
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|      4 | doCall                           in BootStrap$_closure1
|    290 | evaluateEnvironmentSpecificBlock in grails.util.Environment
|    283 | executeForEnvironment            in     ''
|    259 | executeForCurrentEnvironment . . in     ''
|    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

1 个答案:

答案 0 :(得分:1)

withHttp或rest-plugin添加的任何方法都被注入Controllers和Services而不是BootStrap类。请在服务或控制器中尝试。 干杯。 伯纳