Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue wiring together spring-data-neo4j standalone spring project

I'm trying to create a sandbox using spring to handle dependency injection. My sandbox is several domain classes, as well as a MainClass, which has a main(String[] args) method in it.

In annotating my TestClass with @Component and it just contains

@Autowired
private Neo4jTemplate neo4jTemplate;

in it.

In my main method, I call ClassPathXmlApplicationContext on my applicationContext.xml file, which is made up of:

<context:annotation-config/>
<context:spring-configured/>
<context:component-scan base-package="org.neuralsandbox"/>

<neo4j:config storeDirectory="data/sandbox.db"/>

but my program fails to execute at the line here I declare my ClassPathXmlApplicationContext, with a massive stack trace, I'll print the first and last throwables.

First:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testClass': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.data.neo4j.support.Neo4jTemplate org.neuralsandbox.TestClass.neo4jTemplate; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'neo4jTemplate' defined in class org.springframework.data.neo4j.config.Neo4jConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public final org.springframework.data.neo4j.support.Neo4jTemplate org.springframework.data.neo4j.config.Neo4jConfiguration$$EnhancerByCGLIB$$a3874640.neo4jTemplate() throws java.lang.Exception] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mappingInfrastructure' defined in class org.springframework.data.neo4j.config.Neo4jConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public final org.springframework.data.neo4j.support.MappingInfrastructure org.springframework.data.neo4j.config.Neo4jConfiguration$$EnhancerByCGLIB$$a3874640.mappingInfrastructure() throws java.lang.Exception] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'neo4jTransactionManager' defined in class org.springframework.data.neo4j.config.Neo4jConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public final org.springframework.transaction.PlatformTransactionManager org.springframework.data.neo4j.config.Neo4jConfiguration$$EnhancerByCGLIB$$a3874640.neo4jTransactionManager()] threw exception; nested exception is java.lang.NoSuchMethodError: org.neo4j.kernel.impl.transaction.UserTransactionImpl.<init>(Lorg/neo4j/graphdb/GraphDatabaseService;)V
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1073)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:516)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at org.neuralsandbox.MainClass.main(MainClass.java:8)

Last:

Caused by: java.lang.NoSuchMethodError: org.neo4j.kernel.impl.transaction.UserTransactionImpl.<init>(Lorg/neo4j/graphdb/GraphDatabaseService;)V
    at org.springframework.data.neo4j.config.Neo4jConfiguration.createJtaTransactionManager(Neo4jConfiguration.java:240)
    at org.springframework.data.neo4j.config.Neo4jConfiguration.neo4jTransactionManager(Neo4jConfiguration.java:232)
    at org.springframework.data.neo4j.config.Neo4jConfiguration$$EnhancerByCGLIB$$a3874640.CGLIB$neo4jTransactionManager$21(<generated>)
    at org.springframework.data.neo4j.config.Neo4jConfiguration$$EnhancerByCGLIB$$a3874640$$FastClassByCGLIB$$ed4fda1e.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:210)
    at org.springframework.data.neo4j.config.Neo4jConfiguration$$EnhancerByCGLIB$$a3874640.neo4jTransactionManager(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:145)
    ... 72 more

I'm using neo4j 1.7 and spring-data-neo4j 2.0.0.RELEASE, as well as spring 3.1.0.RELEASE.

I haven't found a good reason, using the tutorials provided at spring-data-neo4j, for why it would be throwing this exception. Can anyone help?

like image 252
Nicholas Avatar asked May 25 '12 03:05

Nicholas


1 Answers

I found that this is an issue with the mix of spring-data-neo4j and neo4j that I was using.

In spring-data-neo4j 2.0.1.RELEASE, Neo4jConfiguration is trying to use SpringTransactionManager and UserTransactionImpl that take in an AbstractGraphDatabase class, and in neo4j 1.7 SpringTransactionManager does not take it, and in neo4j 1.8.M01, UserTransactionImpl doesn't take it.

So the resolution for now is to use neo4j 1.6.2 and spring-data-neo4j 2.0.1.RELEASE.

like image 72
Nicholas Avatar answered Sep 22 '22 17:09

Nicholas