私は Spring Data を初めて使用し、Spring Data Neo4j 4.0.0.M1 テストを構成しようとしています。結果が得られずに2日かかりましたが、SDN4でこれを行う例が見つからないようです。
ここに私の簡単なテストクラスがあります:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = MyConfigurationTest.class)
@DirtiesContext
public class ProjectRepositoryTests {
@Autowired
PlatformTransactionManager transactionManager;
@Autowired
ProjectRepository projectRepository;
@Transactional
@Test
public void testAddProject() {
Project project = new Project();
project.setName("ProjectA");
project.setCreationDate(new Date());
project.setDescription("Description");
projectRepository.save(project);
Project addedProject = projectRepository.findProjectByName("ProjectA");
Assert.assertNotNull("should have found something", addedProject);
projectRepository.delete(addedProject);
}
}
ここに私の構成クラスがあります:
@Configuration
@EnableNeo4jRepositories(basePackages = "project.repository")
@EnableTransactionManagement
public class MyConfigurationTest extends Neo4jConfiguration {
@Bean
public Neo4jServer neo4jServer() {
return new InProcessServer();
}
@Bean
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public Session getSession() throws Exception {
return super.getSession();
}
@Bean
public SessionFactory getSessionFactory() {
// with domain entity base package(s)
return new SessionFactory("project.domain");
}
}
ここに私の依存関係があります:
dependencies {
compile "org.springframework.data:spring-data-neo4j:${SDNVersion}"
compile "com.rabbitmq:amqp-client:${RMQVersion}"
compile "com.google.code.gson:gson:${GSONVersion}"
compile "org.neo4j:neo4j:${Neo4jVersion}"
compile "com.graphaware.neo4j:timetree:${Neo4jTimeTreeVersion}"
testCompile group: 'org.neo4j', name: 'neo4j-ogm-test', version: '1.0.0.BUILD-SNAPSHOT', classifier: 'tests'
testCompile group: 'org.springframework.data', name: 'spring-data-neo4j', version: SDNVersion, classifier: 'tests'
testCompile group: 'org.springframework', name: 'spring-test', version: SpringTestVersion
testCompile group: 'junit', name: 'junit', version: '4.11'
}
問題は、次のエラーが発生したことです。
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:94)
at org.springframework.test.context.DefaultTestContext.getApplicationContext(DefaultTestContext.java:72)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:212)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:200)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:259)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:261)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:219)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:83)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:68)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:163)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:78)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'neo4jServer' defined in class MyConfigurationTest: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.neo4j.server.Neo4jServer MyConfigurationTest.neo4jServer()] threw exception; nested exception is java.lang.NoClassDefFoundError: org/neo4j/server/helpers/CommunityServerBuilder
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:597)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1095)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:990)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:706)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:762)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:125)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:109)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:261)
at org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:68)
at org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:86)
... 28 more
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.neo4j.server.Neo4jServer MyConfigurationTest.neo4jServer()] threw exception; nested exception is java.lang.NoClassDefFoundError: org/neo4j/server/helpers/CommunityServerBuilder
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:188)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:586)
... 45 more
Caused by: java.lang.NoClassDefFoundError: org/neo4j/server/helpers/CommunityServerBuilder
at org.springframework.data.neo4j.server.InProcessServer.<init>(InProcessServer.java:31)
at MyConfigurationTest.neo4jServer(MyConfigurationTest.java:23)
at MyConfigurationTest$$EnhancerBySpringCGLIB$$44afa770.CGLIB$neo4jServer$0(<generated>)
at MyConfigurationTest$$EnhancerBySpringCGLIB$$44afa770$$FastClassBySpringCGLIB$$d8d802f1.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:311)
at MyConfigurationTest$$EnhancerBySpringCGLIB$$44afa770.neo4jServer(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:166)
... 46 more
Caused by: java.lang.ClassNotFoundException: org.neo4j.server.helpers.CommunityServerBuilder
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 58 more
事前に感謝します。どんな助けでも本当に感謝します!