3

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

4

3 回答 3

28

将 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"在存储库部分。

于 2011-09-11T16:47:32.570 回答
5

REST 客户端插件

  • 安装:

    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
    }
    
于 2011-09-11T16:17:36.340 回答
0

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

compile ":rest:0.7"

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

于 2013-09-30T16:06:11.633 回答