gpt4 book ai didi

spring - 问题将 spring-data-neo4j 独立 spring 项目连接在一起

转载 作者:行者123 更新时间:2023-12-04 15:02:12 25 4
gpt4 key购买 nike

我正在尝试使用 spring 创建一个沙箱来处理依赖注入(inject)。我的沙箱是几个域类,还有一个 MainClass ,其中有 main(String[] args)里面的方法。

在注释我的 TestClass@Component它只包含

@Autowired
private Neo4jTemplate neo4jTemplate;

在里面。

在我的 main方法,我调用 ClassPathXmlApplicationContext在我的 applicationContext.xml文件,它由以下部分组成:
<context:annotation-config/>
<context:spring-configured/>
<context:component-scan base-package="org.neuralsandbox"/>

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

但是我的程序无法在此处执行我声明我的 ClassPathXmlApplicationContext ,通过大量的堆栈跟踪,我将打印第一个和最后一个 throwable。

第一的:
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)

最后的:
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

我正在使用 neo4j 1.7 和 spring-data-neo4j 2.0.0.RELEASE,以及 spring 3.1.0.RELEASE。

我没有找到一个很好的理由,使用 spring-data-neo4j 提供的教程,为什么它会抛出这个异常。任何人都可以帮忙吗?

最佳答案

我发现这是我使用的 spring-data-neo4j 和 neo4j 混合的问题。

在 spring-data-neo4j 2.0.1.RELEASE 中,Neo4jConfiguration正在尝试使用 SpringTransactionManagerUserTransactionImpl接受 AbstractGraphDatabase类,在 neo4j 1.7 SpringTransactionManager不接受它,在 neo4j 1.8.M01 中,UserTransactionImpl不接受。

所以现在的解决方案是使用 neo4j 1.6.2 和 spring-data-neo4j 2.0.1.RELEASE。

关于spring - 问题将 spring-data-neo4j 独立 spring 项目连接在一起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10748181/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com