赫克托耳与卡桑德拉联系

时间:2011-02-24 01:12:58

标签: java cassandra cassandra-0.7

我试图将cassandra与Hector联系起来:

public class Main {
    public static void main(String[] args) {
        StringSerializer stringSerializer = StringSerializer.get();
        Cluster cluster = HFactory.getOrCreateCluster("Test Cluster", "localhost:9160");
        Keyspace keyspace =  HFactory.createKeyspace("Keyspace1", cluster);
        Mutator<String> mutator = HFactory.createMutator(keyspace, stringSerializer);
        mutator.insert("jsmith", "Standard1", HFactory.createStringColumn("first", "John"));
    }

}

问题:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
    at org.slf4j.LoggerFactory.getSingleton(LoggerFactory.java:230)
    at org.slf4j.LoggerFactory.bind(LoggerFactory.java:121)
    at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:112)
    at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:275)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:248)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:261)
    at me.prettyprint.cassandra.service.AbstractCluster.<init>(AbstractCluster.java:43)
    at me.prettyprint.cassandra.service.AbstractCluster.<init>(AbstractCluster.java:57)
    at me.prettyprint.cassandra.service.ThriftCluster.<init>(ThriftCluster.java:17)
    at me.prettyprint.hector.api.factory.HFactory.createCluster(HFactory.java:112)
    at me.prettyprint.hector.api.factory.HFactory.getOrCreateCluster(HFactory.java:104)
    at me.prettyprint.hector.api.factory.HFactory.getOrCreateCluster(HFactory.java:96)
    at javaapplication1.Main.main(Main.java:25)
Caused by: java.lang.ClassNotFoundException: org.slf4j.impl.StaticLoggerBinder
    at java.net.URLClassLoader$1.run(URLClassLoader.java:276)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:265)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:264)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:325)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:270)
    ... 13 more
Java Result: 1

我怎么解决?

我对hector和cassandra的最后耐心,我试图连接并失败。 我运行twissjava示例并且它可以工作,但是当我扩展主类来进行自己的测试时,它不会运行。

3 个答案:

答案 0 :(得分:3)

此问题“记录在"SLF4J in Hector"-page

上的wiki上

简短版本:您需要添加一个实现SLF4J api的库。

答案 1 :(得分:2)

您使用的是哪种开发环境?

我在netbeans中遇到了同样的问题。 以下是您需要的文件(但请注意您使用的版本)。

log4j下载:http://www.findjar.com/jar/log4j/log4j/1.2.11/log4j-1.2.11.jar.html slf4j下载:http://www.findjar.com/jar/de/huxhorn/lilith/de.huxhorn.lilith.slf4j/0.9.35/de.huxhorn.lilith.slf4j-0.9.35.jar.html

P.S。在findjar网站上搜索正确的版本,如果这些版本不起作用,但我正在使用这两个与cassandra 1.0.7和hector 1.0.2并且他们为我工作。

答案 2 :(得分:1)

你必须在你的类路径中添加像SLF4j,Log4j这样的Hector依赖项,然后你的问题就会解决..我遇到了完全相同的问题,我的问题解决了......我的英语是...:D