CouchDB java.lang.ClassNotFoundException:org.apache.http.impl.client.cache.CacheConfig

k7fdbhmy  于 2022-12-09  发布在  CouchDB
关注(0)|答案(1)|浏览(215)

我正在尝试使用CouchDB与JAVA。这是可怕的!!!这里的代码,我发现在网上:

package project.couchdb;

import java.net.MalformedURLException;
import org.ektorp.CouchDbConnector;
import org.ektorp.CouchDbInstance;
import org.ektorp.http.HttpClient;
import org.ektorp.http.StdHttpClient;
import org.ektorp.impl.StdCouchDbConnector;
import org.ektorp.impl.StdCouchDbInstance;
import org.ektorp.support.DesignDocument;

public class CouchConnect {

    public static void main(String[] args) throws MalformedURLException{

        //connection
        HttpClient client = new StdHttpClient.Builder().url("http://127.0.0.1:5984").build();
        CouchDbInstance dbIstance = new StdCouchDbInstance(client);

        //database
        CouchDbConnector db = new StdCouchDbConnector("test", dbIstance);
        db.createDatabaseIfNotExists();

        //document
        DesignDocument doc = new DesignDocument("test_doc");
        db.create(doc);
    }
}

错误:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/impl/client/cache/CacheConfig
    at org.ektorp.http.StdHttpClient$WithCachingBuilder.withCaching(StdHttpClient.java:533)
    at org.ektorp.http.StdHttpClient$Builder.build(StdHttpClient.java:523)
    at project.couchdb.CouchConnect.main(CouchConnect.java:18)
Caused by: java.lang.ClassNotFoundException: org.apache.http.impl.client.cache.CacheConfig
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 3 more

我刚刚添加了一些.jar,因为控制台给我错误,如'ClassNotFoundException',但这次我找不到要添加的.jar文件。有人链接下载.jar或任何其他解决方案吗?
PS:我在Windows10上使用Eclipse,如果它相关的话
在添加剩余的.jar之后,我发现了以下错误:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.http.client.utils.URLEncodedUtils.parsePathSegments(Ljava/lang/CharSequence;)Ljava/util/List;
    at org.apache.http.impl.client.cache.CacheKeyGenerator.getRequestUri(CacheKeyGenerator.java:78)
    at org.apache.http.impl.client.cache.CacheKeyGenerator.getURI(CacheKeyGenerator.java:118)
    at org.apache.http.impl.client.cache.CacheInvalidator.flushInvalidatedCacheEntries(CacheInvalidator.java:86)
    at org.apache.http.impl.client.cache.BasicHttpCache.flushInvalidatedCacheEntriesFor(BasicHttpCache.java:361)
    at org.apache.http.impl.client.cache.CachingHttpClient.flushEntriesInvalidatedByRequest(CachingHttpClient.java:596)
    at org.apache.http.impl.client.cache.CachingHttpClient.execute(CachingHttpClient.java:457)
    at org.apache.http.impl.client.cache.CachingHttpClient.execute(CachingHttpClient.java:345)
    at org.ektorp.http.StdHttpClient.executeRequest(StdHttpClient.java:177)
    at org.ektorp.http.StdHttpClient.executeRequest(StdHttpClient.java:192)
    at org.ektorp.http.StdHttpClient.head(StdHttpClient.java:146)
    at org.ektorp.http.RestTemplate.head(RestTemplate.java:109)
    at org.ektorp.impl.StdCouchDbInstance.checkIfDbExists(StdCouchDbInstance.java:98)
    at org.ektorp.impl.StdCouchDbInstance.createDatabaseIfNotExists(StdCouchDbInstance.java:63)
    at org.ektorp.impl.StdCouchDbInstance.createDatabaseIfNotExists(StdCouchDbInstance.java:59)
    at org.ektorp.impl.StdCouchDbConnector.createDatabaseIfNotExists(StdCouchDbConnector.java:413)
    at project.couchdb.CouchConnect.main(CouchConnect.java:23)
jtoj6r0c

jtoj6r0c1#

在库列表中还需要httpclient-cache。
现在说它“可怕”似乎还为时过早。

相关问题