【问题标题】:How to install and use httpbuilder plugin in grails如何在 grails 中安装和使用 httpbuilder 插件
【发布时间】:2011-09-11 16:03:32
【问题描述】:

如何在 Grails 中安装和使用 httpbuilder 插件?

【问题讨论】:

  • 没有名为“httpbuilder”的插件。不过有一个REST Client 插件。在documentation 中是否有关于它的安装或使用不清楚的地方?您的问题相当广泛。

标签: grails groovy httpbuilder


【解决方案1】:

将 httpbuilder 0.5.1 添加到您的应用程序依赖项将导致错误。特别是,您会收到如下错误:

java.lang.LinkageError: loader constraint violation: when resolving overridden method "org.apache.xerces.jaxp.SAXParserImpl.getParser()Lorg/xml/sax/Parser;" the class loader (instance of org/codehaus/groovy/grails/cli/support/GrailsRootLoader) of the current class, org/apache/xerces/jaxp/SAXParserImpl, and its superclass loader (instance of <bootloader>), have different Class objects for the type org/xml/sax/Parser used in the signature

我认为问题在于 httpbuilder 将其编译时依赖项导出为运行时依赖项。一个简单的解决方法是在 BuildConfig.groovy 中声明这样的依赖项:

grails.project.dependency.resolution = {
    ...
    dependencies {
        runtime('org.codehaus.groovy.modules.http-builder:http-builder:0.5.1') {
            excludes 'xalan'
            excludes 'xml-apis'
            excludes 'groovy'
        }
    }
}   

我认为您在存储库部分也需要mavenRepo "http://repository.codehaus.org"

【讨论】:

  • 你摇滚阿泰勒!解决了我的下午
  • Codehaus 现在已经死了。因此这个答案需要更新
【解决方案2】:

REST Client plugin

  • 安装:

    grails install-plugin rest
    
  • 例子:

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

【讨论】:

  • 发帖收不到怎么办?
  • 我没有读过文档或曾经使用过这个插件,但我没有受过教育的猜测是将get替换为post
  • 请注意,从 2.3 开始,install-plugin can no longer be used to install plugins。我现在还在想办法解决这个问题,我真的很想念 node/npm :(
【解决方案3】:

我最终使用了 ataylor 的上述步骤,但随后注释掉了该块并测试了插件:

compile ":rest:0.7"

Rest 插件使用 http-builder 并且没有上述依赖项,我的应用程序仍然可以正常工作并通过 http builder 进行调用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-13
    • 1970-01-01
    • 2011-10-21
    • 1970-01-01
    相关资源
    最近更新 更多