运行简单的Neo4J测试时,NoClassDefFoundError com / google / inject / Injector

时间:2016-06-09 16:26:54

标签: java neo4j

我正在尝试编写嵌入式Neo4J Java 1.8应用程序。我按照开发人员的手册尝试运行一个简单的测试来初始化本地测试数据库:

 @Test
 public void initNeo4J() {
     graphDb = new TestGraphDatabaseFactory().newImpermanentDatabase();
 }

我发现运行时异常的根本原因是:

 Caused by: java.lang.NoClassDefFoundError: com/google/inject/Injector

如果我将Google Guice添加到类路径中,则此错误消失,一切正常。但是,我没有在任何地方看到这种依赖性,所以我觉得我错过了什么或做错了什么。这只是一个没有文档记录的依赖,还是我错过了一个吸引注入的关键依赖?以下是我当前的依赖项:

 <dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j</artifactId>
    <version>3.0.0</version>
 </dependency>
 <dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j-kernel</artifactId>
    <version>3.0.0</version>
    <scope>test</scope>
    <type>test-jar</type>
 </dependency>
 <dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j-io</artifactId>
    <version>3.0.0</version>
    <scope>test</scope>
    <type>test-jar</type>
 </dependency>

编辑,这是完整的堆栈跟踪:

java.lang.RuntimeException: Error starting org.neo4j.test.TestGraphDatabaseFactory$1$1, C:\project\socialalpha\socialalpha-spark\neo4j-dev\target\test-data\impermanent-db
    at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.newFacade(GraphDatabaseFacadeFactory.java:144)
    at org.neo4j.kernel.impl.factory.CommunityFacadeFactory.newFacade(CommunityFacadeFactory.java:40)
    at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.newFacade(GraphDatabaseFacadeFactory.java:108)
    at org.neo4j.test.TestGraphDatabaseFactory$1.newDatabase(TestGraphDatabaseFactory.java:232)
    at org.neo4j.graphdb.factory.GraphDatabaseBuilder.newGraphDatabase(GraphDatabaseBuilder.java:183)
    at org.neo4j.test.TestGraphDatabaseFactory.newImpermanentDatabase(TestGraphDatabaseFactory.java:60)
    at com.sa.TestNeo4J.initNeo4J(TestNeo4J.java:43)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:514)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:215)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142)
    at org.testng.internal.Invoker.invokeBeforeGroupsConfigurations(Invoker.java:857)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:581)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
    at org.testng.TestRunner.privateRun(TestRunner.java:782)
    at org.testng.TestRunner.run(TestRunner.java:632)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
    at org.testng.SuiteRunner.run(SuiteRunner.java:268)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
    at org.testng.TestNG.run(TestNG.java:1064)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:137)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:58)
Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.kernel.impl.util.Neo4jJobScheduler@5629510' failed to initialize. Please see attached cause exception.
    at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.init(LifeSupport.java:416)
    at org.neo4j.kernel.lifecycle.LifeSupport.init(LifeSupport.java:62)
    at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:98)
    at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.newFacade(GraphDatabaseFacadeFactory.java:140)
    ... 34 more
Caused by: java.lang.NoClassDefFoundError: com/google/inject/Injector
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.getDeclaredMethod(Class.java:2128)
    at org.neo4j.kernel.impl.util.DebugUtil.trackTest(DebugUtil.java:300)
    at org.neo4j.kernel.impl.util.Neo4jJobScheduler.init(Neo4jJobScheduler.java:46)
    at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.init(LifeSupport.java:406)
    ... 37 more
Caused by: java.lang.ClassNotFoundException: com.google.inject.Injector
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 43 more

2 个答案:

答案 0 :(得分:4)

这是Neo4j中的一个错误。

暂时,您可以添加Guice:

<dependency>
    <groupId>com.google.inject</groupId>
    <artifactId>guice</artifactId>
    <version>4.2.0</version>
</dependency>

即将发布官方修正,您可以按照issue #10722

有关详细信息:https://github.com/neo4j/neo4j/issues/10722#issuecomment-374417890

答案 1 :(得分:0)

最终我意识到这是由于类路径上的其他冲突,很可能是Google Guava的旧版本/新版本。