2014-01-25 295 views
0

我評估了一些訪問neo4j(2.0.0)的堆棧並且在spring(3.2.6)中遇到了一些問題。我現在想要實現的目標非常簡單:連接圖形和讀取節點的單元測試。我的應用程序上下文是這樣的:Spring Data Neo4j失敗junit測試設置

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" 
    xmlns:neo4j="http://www.springframework.org/schema/data/neo4j" 
    xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
    http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx-3.2.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.2.xsd 
    http://www.springframework.org/schema/data/neo4j 
    http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd"> 

    <context:annotation-config /> 
    <context:spring-configured /> 
    <context:component-scan base-package="net.vhite.kin"> 
     <context:exclude-filter type="annotation" 
      expression="org.springframework.stereotype.Controller" /> 
    </context:component-scan> 

    <tx:annotation-driven mode="proxy" /> 

    <neo4j:config graphDatabaseService="graphDatabaseService" /> 
    <bean id="graphDatabaseService" 
     class="org.springframework.data.neo4j.rest.SpringRestGraphDatabase"> 
     <constructor-arg index="0" value="http://192.168.201.2:7474/db/data" /> 
    </bean> 
</beans> 

測試本身是很簡單,太:

@RunWith(SpringJUnit4ClassRunner.class) 
@ContextConfiguration(locations={"test-context.xml"}) 
public class NeoTest { 

    @Autowired 
    Neo4jTemplate template; 

    @Test 
    @Transactional 
    public void persistedMovieShouldBeRetrievableFromGraphDb() { 
     // still empty yet 
    } 
} 

運行這個(空)測試創建應用程序上下文時失敗。我設法解決了很多錯誤,主要是通過修復依賴關係樹,但這個我不明白。異常告訴我一個節點不可用 - 但我還沒有發送任何查詢!所以它與初始化有關。我不知道爲什麼。我搜索了該蹤跡中的每一個異常,但沒有找到一個好的提示。

我做的最後一件事是添加驗證api(1.1.0)。我使用彈簧數據3.0.0的spring 3.2.6,這可能是一個問題嗎?

[main] ERROR org.springframework.test.context.TestContextManager - Caught exception while allowing TestExecutionListener [org.springframewor[email protected]a1a139] to prepare test instance [[email protected]] 
java.lang.IllegalStateException: Failed to load ApplicationContext 
    at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99) 
    at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:122) 
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109) 
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75) 
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:312) 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211) 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288) 
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:284) 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231) 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88) 
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) 
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) 
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) 
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) 
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) 
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) 
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) 
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) 
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71) 
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309) 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174) 
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) 
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'nodeTypeRepresentationStrategy' defined in class org.springframework.data.neo4j.config.Neo4jConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.neo4j.core.TypeRepresentationStrategy org.springframework.data.neo4j.config.Neo4jConfiguration.nodeTypeRepresentationStrategy() throws java.lang.Exception] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'typeRepresentationStrategyFactory' defined in class org.springframework.data.neo4j.config.Neo4jConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.neo4j.support.typerepresentation.TypeRepresentationStrategyFactory org.springframework.data.neo4j.config.Neo4jConfiguration.typeRepresentationStrategyFactory() throws java.lang.Exception] threw exception; nested exception is org.neo4j.graphdb.NotFoundException: Reference node not available 
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:589) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1055) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:951) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:487) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) 
    at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:120) 
    at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) 
    at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:100) 
    at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:248) 
    at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:64) 
    at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:91) 
    ... 27 more 
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.neo4j.core.TypeRepresentationStrategy org.springframework.data.neo4j.config.Neo4jConfiguration.nodeTypeRepresentationStrategy() throws java.lang.Exception] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'typeRepresentationStrategyFactory' defined in class org.springframework.data.neo4j.config.Neo4jConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.neo4j.support.typerepresentation.TypeRepresentationStrategyFactory org.springframework.data.neo4j.config.Neo4jConfiguration.typeRepresentationStrategyFactory() throws java.lang.Exception] threw exception; nested exception is org.neo4j.graphdb.NotFoundException: Reference node not available 
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:181) 
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:578) 
    ... 44 more 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'typeRepresentationStrategyFactory' defined in class org.springframework.data.neo4j.config.Neo4jConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.neo4j.support.typerepresentation.TypeRepresentationStrategyFactory org.springframework.data.neo4j.config.Neo4jConfiguration.typeRepresentationStrategyFactory() throws java.lang.Exception] threw exception; nested exception is org.neo4j.graphdb.NotFoundException: Reference node not available 
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:589) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1055) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:951) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:487) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) 
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:298) 
    at org.springframework.data.neo4j.config.Neo4jConfiguration$$EnhancerByCGLIB$$dd66ab5e.typeRepresentationStrategyFactory(<generated>) 
    at org.springframework.data.neo4j.config.Neo4jConfiguration.nodeTypeRepresentationStrategy(Neo4jConfiguration.java:148) 
    at org.springframework.data.neo4j.config.Neo4jConfiguration$$EnhancerByCGLIB$$dd66ab5e.CGLIB$nodeTypeRepresentationStrategy$1(<generated>) 
    at org.springframework.data.neo4j.config.Neo4jConfiguration$$EnhancerByCGLIB$$dd66ab5e$$FastClassByCGLIB$$41a209a0.invoke(<generated>) 
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) 
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:286) 
    at org.springframework.data.neo4j.config.Neo4jConfiguration$$EnhancerByCGLIB$$dd66ab5e.nodeTypeRepresentationStrategy(<generated>) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
    at java.lang.reflect.Method.invoke(Unknown Source) 
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:160) 
    ... 45 more 
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.neo4j.support.typerepresentation.TypeRepresentationStrategyFactory org.springframework.data.neo4j.config.Neo4jConfiguration.typeRepresentationStrategyFactory() throws java.lang.Exception] threw exception; nested exception is org.neo4j.graphdb.NotFoundException: Reference node not available 
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:181) 
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:578) 
    ... 66 more 
Caused by: org.neo4j.graphdb.NotFoundException: Reference node not available 
    at org.neo4j.rest.graphdb.ExecutingRestAPI.getReferenceNode(ExecutingRestAPI.java:335) 
    at org.neo4j.rest.graphdb.RestAPIFacade.getReferenceNode(RestAPIFacade.java:108) 
    at org.neo4j.rest.graphdb.RestGraphDatabase.getReferenceNode(RestGraphDatabase.java:75) 
    at org.springframework.data.neo4j.support.typerepresentation.LabelBasedNodeTypeRepresentationStrategy.isStrategyAlreadyInUse(LabelBasedNodeTypeRepresentationStrategy.java:129) 
    at org.springframework.data.neo4j.support.typerepresentation.TypeRepresentationStrategyFactory.chooseStrategy(TypeRepresentationStrategyFactory.java:57) 
    at org.springframework.data.neo4j.support.typerepresentation.TypeRepresentationStrategyFactory.<init>(TypeRepresentationStrategyFactory.java:39) 
    at org.springframework.data.neo4j.config.Neo4jConfiguration.typeRepresentationStrategyFactory(Neo4jConfiguration.java:153) 
    at org.springframework.data.neo4j.config.Neo4jConfiguration$$EnhancerByCGLIB$$dd66ab5e.CGLIB$typeRepresentationStrategyFactory$16(<generated>) 
    at org.springframework.data.neo4j.config.Neo4jConfiguration$$EnhancerByCGLIB$$dd66ab5e$$FastClassByCGLIB$$41a209a0.invoke(<generated>) 
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) 
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:286) 
    at org.springframework.data.neo4j.config.Neo4jConfiguration$$EnhancerByCGLIB$$dd66ab5e.typeRepresentationStrategyFactory(<generated>) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
    at java.lang.reflect.Method.invoke(Unknown Source) 
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:160) 
    ... 67 more 
+0

我降級發佈彈簧3.0.0,得到另一個原因:導致:java.lang.NullPointerException \t at org.springframework.data.neo4j.support.DelegatingGraphDatabase.beginTx(DelegatingGraphDatabase.java:251) – avh

回答

1

這是一個版本問題。

SDN 3.0.M01只支持Neo4j的2.0-M06出現了大量的API變更後,SDN 3.0.RC1的下一版本將支持Neo4j的2.0,是由於1月27日2014年

+0

升級到SDN 3.0.0後。 RC1和Spring 3.2.7測試設置工作正常!謝謝! – avh