连接到 Cloudant 客户端 Java
Connect to Cloudant Client Java
我正在尝试连接到 Cloudant 客户端,并且我使用了在 GitHub 上找到的代码示例。
public ClientBuilder getCloudantClient(String username, String password) {
ClientBuilder clientBuilder = ClientBuilder.account(username).
username(username).password(password);
return clientBuilder;
}
理想情况下,一旦该方法 returns,我尝试通过以下方式构建和 return 数据库:
CloudantClient client = (CloudantClient) cloudantRestClient.getCloudantClient(USERNAME, PASSWORD).build();
Database database = client.database(DATABASE, true);
但由于某种原因,我遇到了编译错误:
The method account(String) is undefined for the type ClientBuilder
我的 pom.xml Cloudant 和 JUnit 测试依赖项如下:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.cloudant</groupId>
<artifactId>cloudant-client</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.22.1</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
</dependency>
我不确定我哪里出错了。这是正确的方法吗?
您导入了错误的 ClientBuilder,检查它确实是 com.cloudant.client.api.ClientBuilder
我正在尝试连接到 Cloudant 客户端,并且我使用了在 GitHub 上找到的代码示例。
public ClientBuilder getCloudantClient(String username, String password) {
ClientBuilder clientBuilder = ClientBuilder.account(username).
username(username).password(password);
return clientBuilder;
}
理想情况下,一旦该方法 returns,我尝试通过以下方式构建和 return 数据库:
CloudantClient client = (CloudantClient) cloudantRestClient.getCloudantClient(USERNAME, PASSWORD).build();
Database database = client.database(DATABASE, true);
但由于某种原因,我遇到了编译错误:
The method account(String) is undefined for the type ClientBuilder
我的 pom.xml Cloudant 和 JUnit 测试依赖项如下:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.cloudant</groupId>
<artifactId>cloudant-client</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.22.1</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
</dependency>
我不确定我哪里出错了。这是正确的方法吗?
您导入了错误的 ClientBuilder,检查它确实是 com.cloudant.client.api.ClientBuilder