我尝试使用 Cassandra 后端访问 Titan 图形数据库,并且使用以下代码一切正常:
package ch.uzh.ifi.ddis.dm.twhc.clusterhierarchy;
import ch.uzh.ifi.ddis.dm.twhc.clusterhierarchy.persistence.ITreeSerializer;
import ch.uzh.ifi.ddis.dm.twhc.clusterhierarchy.persistence.TitanSerializer;
public class ConnectionOkDriver {
public static void main(String[] args) {
ITreeSerializer serializer = TitanSerializer.getInstance();
if (serializer.dbConnected()) {
System.out.print("connection ok");
} else {
System.out.print("connection NOT ok");
}
}
}
输出(忽略 SLF4J 错误):
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.
connection ok
现在,如果我启动以下主要方法,则会出现Could not instantiate implementation
错误:
package ch.uzh.ifi.ddis.dm.twhc.input;
import ch.uzh.ifi.ddis.dm.twhc.clusterhierarchy.persistence.ITreeSerializer;
import ch.uzh.ifi.ddis.dm.twhc.clusterhierarchy.persistence.TitanSerializer;
public class ConnectionFailsDriver {
public static void main(String[] args) {
ITreeSerializer serializer = TitanSerializer.getInstance();
if (serializer.dbConnected()) {
System.out.print("connection ok");
} else {
System.out.print("connection NOT ok");
}
}
}
输出(再次忽略 SLF4J 错误):
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.ExceptionInInitializerError
at ch.uzh.ifi.ddis.dm.twhc.input.ConnectionFailsDriver.main(ConnectionFailsDriver.java:9)
Caused by: java.lang.IllegalArgumentException: Could not instantiate implementation: com.thinkaurelius.titan.diskstorage.cassandra.astyanax.AstyanaxStoreManager
at com.thinkaurelius.titan.diskstorage.Backend.getImplementationClass(Backend.java:274)
at com.thinkaurelius.titan.diskstorage.Backend.getStorageManager(Backend.java:227)
at com.thinkaurelius.titan.diskstorage.Backend.<init>(Backend.java:97)
at com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration.getBackend(GraphDatabaseConfiguration.java:440)
at com.thinkaurelius.titan.graphdb.database.StandardTitanGraph.<init>(StandardTitanGraph.java:67)
at com.thinkaurelius.titan.core.TitanFactory.open(TitanFactory.java:40)
at ch.uzh.ifi.ddis.dm.twhc.clusterhierarchy.persistence.TitanSerializer.<init>(TitanSerializer.java:88)
at ch.uzh.ifi.ddis.dm.twhc.clusterhierarchy.persistence.TitanSerializer.<clinit>(TitanSerializer.java:78)
... 1 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.thinkaurelius.titan.diskstorage.Backend.getImplementationClass(Backend.java:263)
... 8 more
Caused by: java.lang.NoSuchMethodError: com.netflix.astyanax.AstyanaxContext.getClient()Ljava/lang/Object;
at com.thinkaurelius.titan.diskstorage.cassandra.astyanax.AstyanaxStoreManager.<init>(AstyanaxStoreManager.java:166)
... 13 more
如您所见,这些类ConnectionOkDriver
仅ConnectionFailsDriver
在包定义上有所不同。但是,这两个类包含在不同的 maven 模块中(2whc-clustering-impl 依赖于 2whc-cluster-hierarchy-impl)。我想发布我的项目结构的图像,但我不允许这样做:(。这是图像的链接:https://dl.dropboxusercontent.com/u/48169775/project-structure。 PNG
错误发生在我的TitanSerializer
对象的构造函数中TitanFactory.open(conf)
。这是代码:
private static final String DB_TYPE = "cassandra";
private static final String DB_IP = "127.0.0.1";
private TitanSerializer() {
Configuration conf = new BaseConfiguration();
conf.setProperty("storage.backend", DB_TYPE);
conf.setProperty("storage.hostname", DB_IP);
this.graph = TitanFactory.open(conf);
.
.
.
}
你知道我为什么会收到这个错误吗?