java.lang.NoSuchMethodError:org.neo4j.kernel.impl.transaction.SpringTransactionManager。<init>(Lorg / neo4j / graphdb / GraphDatabaseService;)V </init>

时间:2012-10-29 18:36:33

标签: spring neo4j spring-data-neo4j

我开始学习spring-data-neo4j

非常基本的测试用例我正在运行但无法成功。 错误是:java.lang.IllegalStateException: Failed to load ApplicationContext

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'neo4jRelationshipBacking' defined in class path resource [org/springframework/data/neo4j/aspects/config/Neo4jAspectConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.neo4j.aspects.support.relationship.Neo4jRelationshipBacking org.springframework.data.neo4j.aspects.config.Neo4jAspectConfiguration.neo4jRelationshipBacking() throws java.lang.Exception] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'neo4jTemplate' defined in class path resource [org/springframework/data/neo4j/aspects/config/Neo4jAspectConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.neo4j.support.Neo4jTemplate org.springframework.data.neo4j.config.Neo4jConfiguration.neo4jTemplate() throws java.lang.Exception] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mappingInfrastructure' defined in class path resource [org/springframework/data/neo4j/aspects/config/Neo4jAspectConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.neo4j.support.MappingInfrastructureFactoryBean org.springframework.data.neo4j.config.Neo4jConfiguration.mappingInfrastructure() throws java.lang.Exception] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'neo4jTransactionManager' defined in class path resource [org/springframework/data/neo4j/aspects/config/Neo4jAspectConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.transaction.PlatformTransactionManager org.springframework.data.neo4j.config.Neo4jConfiguration.neo4jTransactionManager()] threw exception; nested exception is java.lang.NoSuchMethodError: org.neo4j.kernel.impl.transaction.SpringTransactionManager.<init>(Lorg/neo4j/graphdb/GraphDatabaseService;)V

User.java pojo用@NodeEntity

注释
@NodeEntity
public class User {
    @GraphId
    private Long id;

    User(String name){
        this.name = name;
    }
    private String name;

    public Long getId() {
        return id;
    }

    public String getName() {
        return name;
    }

}

配置文件是:

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

    <context:annotation-config/>
    <context:spring-configured/>

    <neo4j:config  storeDirectory="D:/data/db"/>
    <tx:annotation-driven mode="proxy"/>
    <context:component-scan base-package="com.neo4j.model"/>
</beans>

JUnit测试用例

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:/graph-test-context.xml"})
public class Neo4jUserTest {

    @Autowired
    Neo4jTemplate neo4jTemplate;
    @Test
    public void test() {
        User user = new User("test");
        neo4jTemplate.beginTx();
        neo4jTemplate.save(user);
    }
}

我已经从eclipse构建路径手动添加了以下jar文件:

commons-logging-1.0.4.jar
log4j-1.2.15.jar
jta.jar
cglib-2.1.3.jar
validation-api-1.0.0.GA.jar
lucene-core-3.5.0.jar
servlet-api.jar
org.springframework.aop-3.1.2.RELEASE.jar
org.springframework.asm-3.1.2.RELEASE.jar
org.springframework.aspects-3.1.2.RELEASE.jar
org.springframework.beans-3.1.2.RELEASE.jar
org.springframework.context.support-3.1.2.RELEASE.jar
org.springframework.context-3.1.2.RELEASE.jar
org.springframework.core-3.1.2.RELEASE.jar
org.springframework.expression-3.1.2.RELEASE.jar
org.springframework.instrument.tomcat-3.1.2.RELEASE.jar
org.springframework.instrument-3.1.2.RELEASE.jar
org.springframework.jdbc-3.1.2.RELEASE.jar
org.springframework.jms-3.1.2.RELEASE.jar
org.springframework.orm-3.1.2.RELEASE.jar
org.springframework.oxm-3.1.2.RELEASE.jar
org.springframework.test-3.1.2.RELEASE.jar
org.springframework.transaction-3.1.2.RELEASE.jar
org.springframework.web.portlet-3.1.2.RELEASE.jar
org.springframework.web.servlet-3.1.2.RELEASE.jar
org.springframework.web.struts-3.1.2.RELEASE.jar
org.springframework.web-3.1.2.RELEASE.jar
D:\JUnit\junit-4.6.jar
com.springsource.org.aopalliance-1.0.0.jar
aspectjtools-1.6.0.jar
asm-attrs.jar
asm.jar
spring-data-neo4j-2.1.0.RC1.jar
spring-data-neo4j-aspects-2.1.0.RC1.jar
spring-data-neo4j-cross-store-2.1.0.RC1.jar
spring-data-neo4j-rest-2.1.0.RC1.jar
slf4j-api-1.6.1.jar
slf4j-log4j12-1.7.2.jar
geronimo-jta_1.1_spec-1.1.1.jar
lucene-core-3.5.0.jar
org.apache.servicemix.bundles.jline-0.9.94_1.jar
scala-library-2.9.0-1.jar
server-api-1.7.2.jar
spring-data-commons-core-1.3.1.RELEASE.jar
hamcrest-all-1.3.jar
neo4j-cypher-dsl-1.6.M02.jar
neo4j-cypher-1.9-20120912.103508-32.jar
neo4j-kernel-1.9-20120912.102607-33.jar
neo4j-lucene-index-1.9-20120912.103015-33.jar

3 个答案:

答案 0 :(得分:2)

正如Peter所说,问题是你要包含一个不同于Spring期望的Neo4J库的不同版本。 NoSuchMethodError 表示客户端正在调用不存在的方法。如果你包含Spring正在使用的版本,那么就不会发生这种情况如果他们调用了一个不存在的方法,那么Spring会遇到编译错误。

你是如何建立项目的?如果它是一个maven项目,请提供更多细节,如POM。

更新 org.neo4j.kernel.impl.transaction.SpringTransactionManager 来自您的Neo4J安装,而不是您提供的罐子。你在运行什么版本的Neo4J?它需要匹配spring-data-neo4j所期望的版本。

答案 1 :(得分:0)

您似乎使用的是旧的Neo4j版本。你能尝试相应的Neo4j版本吗,我认为1.8而不是1.7.2?

答案 2 :(得分:0)

最后我通过使用下面的jar文件来解决它:

aopalliance-1.0.jar
asm-3.1.jar
aspectjrt-1.6.12.jar
backport-util-concurrent-3.1.jar
cglib-2.2.jar
codegen-0.5.5.jar
commons-cli-1.0.jar
ecj-3.7.2.jar
guava-11.0.2.jar
hamcrest-core-1.3.jar
hamcrest-library-1.3.jar
jakarta-regexp-1.4.jar
javax.inject-1.jar
jcl-over-slf4j-1.7.1.jar
jsr305-1.3.9.jar
jta.jar
junit-3.8.1.jar
junit-dep-4.10.jar
logback-classic-1.0.6.jar
logback-core-1.0.6.jar
lucene-core-3.5.0.jar
lucene-queries-3.5.0.jar
mysema-commons-lang-0.2.4.jar
neo4j-1.8.jar
neo4j-cypher-1.8.jar
neo4j-cypher-dsl-1.8.jar
neo4j-graph-algo-1.8.jar
neo4j-graph-matching-1.8.jar
neo4j-jmx-1.8.jar
neo4j-kernel-1.8.jar
neo4j-lucene-index-1.8.jar
neo4j-udc-1.8.jar
plexus-compiler-api-1.9.1.jar
plexus-compiler-javac-1.9.1.jar
plexus-compiler-manager-1.9.1.jar
plexus-interactivity-api-1.0-alpha-4.jar
plexus-interpolation-1.11.jar
plexus-interpolation-1.13.jar
plexus-utils-1.5.15.jar
plexus-utils-2.0.5.jar
plexus-utils-3.0.jar
querydsl-apt-2.8.2.jar
querydsl-codegen-2.8.2.jar
querydsl-core-2.8.2.jar
querydsl-lucene-2.8.2.jar
scala-library-2.9.1-1.jar
slf4j-api-1.7.1.jar
spring-aop-3.2.0.M2.jar
spring-aspects-3.2.0.M2.jar
spring-beans-3.2.0.M2.jar
spring-context-3.2.0.M2.jar
spring-core-3.2.0.M2.jar
spring-data-commons-core-1.4.0.RELEASE.jar
spring-data-neo4j-2.1.0.RELEASE.jar
spring-expression-3.2.0.M2.jar
spring-jdbc-3.2.0.M2.jar
spring-orm-3.2.0.M2.jar
spring-test-3.2.0.M2.jar
spring-tx-3.2.0.M2.jar
validation-api-1.0.0.GA.jar