我無法使用Hector訪問Casandra。以下是代碼無法使用Hector連接到cassandra
import java.util.Arrays;
import java.util.List;
import me.prettyprint.cassandra.service.CassandraHostConfigurator;
import me.prettyprint.cassandra.service.ThriftCluster;
import me.prettyprint.cassandra.service.ThriftKsDef;
import me.prettyprint.hector.api.Cluster;
import me.prettyprint.hector.api.Keyspace;
import me.prettyprint.hector.api.ddl.ColumnFamilyDefinition;
import me.prettyprint.hector.api.ddl.KeyspaceDefinition;
import me.prettyprint.hector.api.factory.HFactory;
import me.prettyprint.hector.api.mutation.Mutator;
public class Hector {
public static void main (String[] args){
boolean cfExists = false;
Cluster cluster = HFactory.getOrCreateCluster("mycluster", new CassandraHostConfigurator("host:9160"));
Keyspace keyspace = HFactory.createKeyspace("Keyspace1", cluster);
// first check if the key space exists
KeyspaceDefinition keyspaceDetail = cluster.describeKeyspace("Keyspace1");
// if not, create one
if (keyspaceDetail == null) {
CassandraHostConfigurator cassandraHostConfigurator = new CassandraHostConfigurator("host:9160");
ThriftCluster cassandraCluster = new ThriftCluster("mycluster", cassandraHostConfigurator);
ColumnFamilyDefinition cfDef = HFactory.createColumnFamilyDefinition("Keyspace1", "base");
cassandraCluster.addKeyspace(new ThriftKsDef("Keyspace1", "org.apache.cassandra.locator.SimpleStrategy", 1,
Arrays.asList(cfDef)));
} else {
// even if the key space exists, we need to check if the column family exists
List<ColumnFamilyDefinition> columnFamilyDefinitions = keyspaceDetail.getCfDefs();
for (ColumnFamilyDefinition def : columnFamilyDefinitions) {
String columnFamilyName = def.getName();
if (columnFamilyName.equals("tcs_im"))
cfExists = true;
}
}
}
}
遭遇以下錯誤
的log4j:警告沒有附加目的地可以爲記錄器(me.prettyprint.cassandra.connection.CassandraHostRetryService)中找到。 log4j:WARN請正確初始化log4j系統。 log4j:警告有關更多信息,請參見http://logging.apache.org/log4j/1.2/faq.html#noconfig。 線程「main」中的異常java.lang.IllegalAccessError:嘗試訪問me.prettyprint.cassandra.connection.HConnectionManager類中的類me.prettyprint.cassandra.connection.HConnectionManager 。 HConnectionManager.java:78) at me.prettyprint.cassandra.service.AbstractCluster。(AbstractCluster.java:69) at me.prettyprint.cassandra.service.AbstractCluster。(AbstractCluster.java:65) at me.prettyprint。在me.prettyprint.hector.api.factory.HFactory.getOrCreateCluster()上的文件(HFactory.java:155) at com.im.tcs.Hector.main(Hector.java:20)
請幫助爲什麼發生。
什麼卡桑德拉和赫克託的版本? IllegalAccessError表明您有一些類的不同版本不兼容... – DNA