使用neo4j 2有效设置spring-data-neo4f

时间:2014-02-08 14:10:29

标签: neo4j spring-data-neo4j

我很难使用spring-data-neo4j和新的neo4j 2.0版设置我的项目(因为我想在neo4j中使用新的标签)

在挖掘之后,我在maven存储库中找到了spring-data-neo4j 3.0.0.RC1。另外,我想使用neo4j-spatial。 相关的maven依赖关系定义如下:

        <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>4.0.0.RELEASE</version>
        <exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>4.0.0.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>4.0.0.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>4.0.0.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>4.0.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-neo4j</artifactId>
        <version>3.0.0.RC1</version>
        <exclusions>
            <exclusion>
                <groupId>org.hibernate.javax.persistence</groupId>
                <artifactId>hibernate-jpa-2.0-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.neo4j</groupId>
        <artifactId>neo4j-spatial</artifactId>
        <version>0.12-neo4j-2.0.0-M06</version>
    </dependency>

应用程序上下文遵循项目网站上的示例:

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

<neo4j:config storeDirectory="target/my.db"/>
<neo4j:repositories base-package="org.some.packages.repository"/>


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

我不使用AspectJ。

当我启动项目时,我得到以下异常:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'someRepository': Invocation of init method failed; nested exception is org.neo4j.graphdb.TransactionFailureException: Unable to commit transaction
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:681)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:121)
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:250)
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:64)
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:91)
Caused by: org.neo4j.graphdb.TransactionFailureException: Unable to commit transaction
at org.neo4j.kernel.TopLevelTransaction.close(TopLevelTransaction.java:134)
at org.springframework.data.neo4j.support.DelegatingGraphDatabase.createIndex(DelegatingGraphDatabase.java:175)
at org.springframework.data.neo4j.support.index.IndexProviderImpl.createIndex(IndexProviderImpl.java:91)
at org.springframework.data.neo4j.support.index.IndexProviderImpl.getIndex(IndexProviderImpl.java:68)
at org.springframework.data.neo4j.support.index.IndexProviderImpl.getIndex(IndexProviderImpl.java:108)

失败的''someomeRepository'''bean是一个扩展GraphRepository的简单接口。

如果spring-data-neo4j(在引擎盖下使用neo4j 1.9),该设置与最新的稳定版本配合使用

有什么想法吗?

修改 我的@NodeEntity之一的属性具有以下索引定义:

    @Indexed(indexType = IndexType.POINT, indexName = "someIndexName", unique = false)

如果删除此索引,则可以启动应用程序上下文。

1 个答案:

答案 0 :(得分:1)

我能够通过在我的pom.xml文件中添加一些其他依赖项来解决这个问题:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>it.larusba.spikes.neo4j</groupId>
<artifactId>neo4art</artifactId>
<version>0.0.1-SNAPSHOT</version>
<description>neo4art spike based on Neo4j, Heroku, GeoSpatial, MapQuest</description>
<packaging>war</packaging>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    <source.level>1.7</source.level>
    <target.level>1.7</target.level>

    <spring.version>4.0.2.RELEASE</spring.version>
    <spring.ws.version>2.1.4.RELEASE</spring.ws.version>
    <castor.version>1.3.3</castor.version>

    <spring.data.neo4j.version>3.0.1.RELEASE</spring.data.neo4j.version>
    <neo4j.spatial.version>0.12-neo4j-2.0.1</neo4j.spatial.version>
    <neo4j.graphcollections.version>0.7.1-neo4j-2.0.1</neo4j.graphcollections.version>
</properties>

<dependencies>

    <!-- Spring -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
        <exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aspects</artifactId>
        <version>${spring.version}</version>
        <scope>runtime</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <!-- Spring Data Neo4j -->
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-neo4j</artifactId>
        <version>${spring.data.neo4j.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-neo4j-rest</artifactId>
        <version>${spring.data.neo4j.version}</version>
    </dependency>

    <!-- Neo4j Geo-Spatial -->
    <dependency>
        <groupId>org.neo4j</groupId>
        <artifactId>neo4j-spatial</artifactId>
        <version>${neo4j.spatial.version}</version>
    </dependency>

    <dependency>
        <groupId>org.neo4j</groupId>
        <artifactId>neo4j-graph-collections</artifactId>
        <version>${neo4j.graphcollections.version}</version>
        <exclusions>
            <exclusion>
                <groupId>org.neo4j</groupId>
                <artifactId>neo4j</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.neo4j</groupId>
                <artifactId>neo4j-lucene-index</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>com.vividsolutions</groupId>
        <artifactId>jts</artifactId>
        <version>1.13</version>
    </dependency>

    <dependency>
        <groupId>com.googlecode.json-simple</groupId>
        <artifactId>json-simple</artifactId>
        <version>1.1.1</version>
    </dependency>

    <dependency>
        <groupId>org.opengis</groupId>
        <artifactId>geoapi</artifactId>
        <version>3.0.0</version>
    </dependency>

     <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-shapefile</artifactId>
        <version>9.2</version>
    </dependency>

    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-swing</artifactId>
        <version>9.2</version>
    </dependency>

    <!-- Necessaria con l'annotazione @Configuration -->
    <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib</artifactId>
        <version>2.2.2</version>
    </dependency>

    <!-- Jackson JSON Mapper -->
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>1.7.1</version>
    </dependency>
    <dependency>
        <groupId>org.codehaus.jettison</groupId>
        <artifactId>jettison</artifactId>
        <version>1.3.5</version>
    </dependency>

    <!-- REST: Marshalling/Unmarshalling XML to OBJECT -->
    <dependency>
       <groupId>org.springframework</groupId>
       <artifactId>spring-oxm</artifactId>
       <version>${spring.version}</version>
    </dependency>
    <dependency>
       <groupId>org.springframework.ws</groupId>
       <artifactId>spring-ws-core</artifactId>
       <version>${spring.ws.version}</version>
    </dependency>
    <dependency>
        <groupId>org.codehaus.castor</groupId>
        <artifactId>castor-xml</artifactId>
        <version>${castor.version}</version>
    </dependency>

    <!-- @Inject -->
    <dependency>
        <groupId>javax.inject</groupId>
        <artifactId>javax.inject</artifactId>
        <version>1</version>
    </dependency>

    <!-- JSR 303 Validator -->
    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>1.0.0.GA</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>4.1.0.Final</version>
    </dependency>

    <!--  Apache Commons -->
    <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
        <version>2.6</version>
    </dependency>
    <dependency>
        <groupId>commons-collections</groupId>
        <artifactId>commons-collections</artifactId>
        <version>3.2.1</version>
    </dependency>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.4</version>
    </dependency>
    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.1.3</version>
    </dependency>
    <dependency>
        <groupId>commons-beanutils</groupId>
        <artifactId>commons-beanutils</artifactId>
        <version>1.8.0</version>
    </dependency>

    <!-- DTO -->
    <dependency>
        <groupId>net.sf.dozer</groupId>
        <artifactId>dozer</artifactId>
        <version>5.4.0</version>
    </dependency>

    <!-- Servlet -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>

    <!-- Logging: slf4j -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
        <version>1.5.8</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.5.8</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.5.8</version>
    </dependency>

    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.14</version>
    </dependency>

    <!-- Test -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.1</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${spring.version}</version>
        <scope>test</scope>
    </dependency>

</dependencies>

<build>

    <plugins>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>${source.level}</source>
                <target>${target.level}</target>
                <encoding>${project.build.sourceEncoding}</encoding>
            </configuration>
        </plugin>

    </plugins>

</build>

<repositories>

    <repository>
        <id>spring-maven-snapshot</id>
        <name>Springframework Maven MILESTONE Repository</name>
        <snapshots><enabled>true</enabled></snapshots>
        <url>http://maven.springframework.org/milestone</url>
    </repository>

    <repository>
        <id>spring-snapshots</id>
        <name>Spring Snapshots</name>
        <snapshots><enabled>true</enabled></snapshots>
        <url>http://repo.spring.io/snapshot</url>
    </repository>       

    <repository>
        <id>neo4j-repository</id>
        <snapshots><enabled>true</enabled></snapshots>
        <name>Neo4j RELEASES Repository</name>
        <url>http://m2.neo4j.org/content/repositories/releases</url>
    </repository>

    <repository>
        <id>osgeo</id>
        <name>Open Source Geospatial Foundation Repository</name>
        <url>http://download.osgeo.org/webdav/geotools/</url>
    </repository>

</repositories> 

<pluginRepositories>

    <pluginRepository>
        <id>spring-plugins-release</id>
        <url>http://libs.spring.io/plugins-release</url>
    </pluginRepository>

</pluginRepositories>

特别请查看“Neo4j Geo-Spatial”部分:我最终能够解决添加这两个地理工具依赖项的同样问题。

我正在使用带有neo4j 2.0.1的SDN 3.0.1

希望会有所帮助。

干杯,

洛伦佐