gpt4 book ai didi

java - 在 Grails 2.4 中使用 HTTPClient

转载 作者:行者123 更新时间:2023-12-01 22:40:05 24 4
gpt4 key购买 nike

Grails 新手,并尝试使用 apache 中的 HttpClient 在集成测试中使用它...所以我将其依赖项放在其中:

dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes e.g.
// runtime 'mysql:mysql-connector-java:5.1.29'
// runtime 'org.postgresql:postgresql:9.3-1101-jdbc41'
test "org.grails:grails-datastore-test-support:1.0-grails-2.4"
compile 'org.apache.httpcomponents:httpcore:4.1.2'
compile 'org.apache.httpcomponents:httpclient:4.1.2'
build 'org.apache.httpcomponents:httpcore:4.1.2'
build 'org.apache.httpcomponents:httpclient:4.1.2'
test 'org.apache.httpcomponents:httpcore:4.1.2'
test 'org.apache.httpcomponents:httpclient:4.1.2'
}

在 build.config 中,并期望能够在像

这样的测试中使用它
class MyControllerTests extends GroovyTestCase {
@Test
void testApacheHttpClient() {
def client = new HttpClient()
}
}

但是我无法让它工作,因为 grails 无法解析任何类。

我尝试过手动导入,但没有成功。

我做错了什么?!

提前致谢。

最佳答案

您缺少 Commons HttpClient 作为依赖项。

您应该将其添加到您的依赖项中:

test 'commons-httpclient:commons-httpclient:3.1'

还要确保在源代码中导入正确的类:

org.apache.commons.httpclient.HttpClient

关于java - 在 Grails 2.4 中使用 HTTPClient,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26303835/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com