ata*_*lor 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
Run Code Online (Sandbox Code Playgroud)
我认为问题在于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'
}
}
}
Run Code Online (Sandbox Code Playgroud)
我认为你也需要mavenRepo "http://repository.codehaus.org"在存储库部分.
有一个REST客户端插件:
安装:
grails install-plugin rest
Run Code Online (Sandbox Code Playgroud)例:
withHttp(uri: "http://www.google.com") {
def html = get(path : '/search', query : [q:'Groovy'])
assert html.HEAD.size() == 1
assert html.BODY.size() == 1
}
Run Code Online (Sandbox Code Playgroud)